forked from M-Labs/artiq
1
0
Fork 0

gui: save/restore state of pyqtgraph plots (closes #98)

This commit is contained in:
Sebastien Bourdeauducq 2015-08-15 15:29:41 +08:00
parent 34a9c8c12d
commit 0be0b199c1
2 changed files with 30 additions and 3 deletions

View File

@ -94,6 +94,12 @@ class NumberDisplay(dockarea.Dock):
n = "---" n = "---"
self.number.display(n) self.number.display(n)
def save_state(self):
return None
def restore_state(self, state):
pass
class XYDisplaySettings(_SimpleSettings): class XYDisplaySettings(_SimpleSettings):
_window_title = "XY plot" _window_title = "XY plot"
@ -155,6 +161,12 @@ class XYDisplay(dockarea.Dock):
if fit is not None: if fit is not None:
self.plot.plot(x, fit) self.plot.plot(x, fit)
def save_state(self):
return self.plot.saveState()
def restore_state(self, state):
self.plot.restoreState(state)
class HistogramDisplaySettings(_SimpleSettings): class HistogramDisplaySettings(_SimpleSettings):
_window_title = "Histogram" _window_title = "Histogram"
@ -191,7 +203,14 @@ class HistogramDisplay(dockarea.Dock):
if y and len(x) == len(y) + 1: if y and len(x) == len(y) + 1:
self.plot.clear() self.plot.clear()
self.plot.plot(x, y, stepMode=True, fillLevel=0, brush=(0, 0, 255, 150)) self.plot.plot(x, y, stepMode=True, fillLevel=0,
brush=(0, 0, 255, 150))
def save_state(self):
return self.plot.saveState()
def restore_state(self, state):
self.plot.restoreState(state)
display_types = OrderedDict([ display_types = OrderedDict([

View File

@ -120,20 +120,28 @@ class ResultsDock(dockarea.Dock):
dsp.sigClosed.connect(on_close) dsp.sigClosed.connect(on_close)
self.dock_area.addDock(dsp) self.dock_area.addDock(dsp)
self.dock_area.floatDock(dsp) self.dock_area.floatDock(dsp)
return dsp
def save_state(self): def save_state(self):
r = dict() r = dict()
for name, display in self.displays.items(): for name, display in self.displays.items():
r[name] = { r[name] = {
"ty": _get_display_type_name(type(display)), "ty": _get_display_type_name(type(display)),
"settings": display.settings "settings": display.settings,
"state": display.save_state()
} }
return r return r
def restore_state(self, state): def restore_state(self, state):
for name, desc in state.items(): for name, desc in state.items():
try: try:
self.create_display(desc["ty"], None, name, desc["settings"]) dsp = self.create_display(desc["ty"], None, name,
desc["settings"])
except: except:
logger.warning("Failed to create display '%s'", name, logger.warning("Failed to create display '%s'", name,
exc_info=True) exc_info=True)
try:
dsp.restore_state(desc["state"])
except:
logger.warning("Failed to restore display state of '%s'",
name, exc_info=True)