Skip to content

Commit

Permalink
gui: save/restore state of pyqtgraph plots (closes #98)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourdeauducq committed Aug 15, 2015
1 parent 34a9c8c commit 0be0b19
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
21 changes: 20 additions & 1 deletion artiq/gui/displays.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def update_data(self, data):
n = "---"
self.number.display(n)

def save_state(self):
return None

def restore_state(self, state):
pass


class XYDisplaySettings(_SimpleSettings):
_window_title = "XY plot"
Expand Down Expand Up @@ -155,6 +161,12 @@ def update_data(self, data):
if fit is not None:
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):
_window_title = "Histogram"
Expand Down Expand Up @@ -191,7 +203,14 @@ def update_data(self, data):

if y and len(x) == len(y) + 1:
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([
Expand Down
12 changes: 10 additions & 2 deletions artiq/gui/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,28 @@ def on_close():
dsp.sigClosed.connect(on_close)
self.dock_area.addDock(dsp)
self.dock_area.floatDock(dsp)
return dsp

def save_state(self):
r = dict()
for name, display in self.displays.items():
r[name] = {
"ty": _get_display_type_name(type(display)),
"settings": display.settings
"settings": display.settings,
"state": display.save_state()
}
return r

def restore_state(self, state):
for name, desc in state.items():
try:
self.create_display(desc["ty"], None, name, desc["settings"])
dsp = self.create_display(desc["ty"], None, name,
desc["settings"])
except:
logger.warning("Failed to create display '%s'", name,
exc_info=True)
try:
dsp.restore_state(desc["state"])
except:
logger.warning("Failed to restore display state of '%s'",
name, exc_info=True)

0 comments on commit 0be0b19

Please sign in to comment.