From 0be0b199c14f654b29272f943c62e59a70d77e7e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 15 Aug 2015 15:29:41 +0800 Subject: [PATCH] gui: save/restore state of pyqtgraph plots (closes #98) --- artiq/gui/displays.py | 21 ++++++++++++++++++++- artiq/gui/results.py | 12 ++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/artiq/gui/displays.py b/artiq/gui/displays.py index 512159c7e..a08aed041 100644 --- a/artiq/gui/displays.py +++ b/artiq/gui/displays.py @@ -94,6 +94,12 @@ class NumberDisplay(dockarea.Dock): n = "---" self.number.display(n) + def save_state(self): + return None + + def restore_state(self, state): + pass + class XYDisplaySettings(_SimpleSettings): _window_title = "XY plot" @@ -155,6 +161,12 @@ class XYDisplay(dockarea.Dock): 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" @@ -191,7 +203,14 @@ class HistogramDisplay(dockarea.Dock): 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([ diff --git a/artiq/gui/results.py b/artiq/gui/results.py index 9c4c321c8..0ed872a6a 100644 --- a/artiq/gui/results.py +++ b/artiq/gui/results.py @@ -120,20 +120,28 @@ class ResultsDock(dockarea.Dock): 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)