From 8ad88438c71fd34a190868a87b44d4fb5f5555ca Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 1 Aug 2015 19:37:16 +0800 Subject: [PATCH] gui: save display state --- artiq/frontend/artiq_gui.py | 1 + artiq/gui/results.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/artiq/frontend/artiq_gui.py b/artiq/frontend/artiq_gui.py index 35f444fa9..74ced8e62 100755 --- a/artiq/frontend/artiq_gui.py +++ b/artiq/frontend/artiq_gui.py @@ -82,6 +82,7 @@ def main(): atexit.register(lambda: loop.run_until_complete(d_explorer.sub_close())) d_results = ResultsDock(win, area) + smgr.register(d_results) loop.run_until_complete(d_results.sub_connect( args.server, args.port_notify)) atexit.register(lambda: loop.run_until_complete(d_results.sub_close())) diff --git a/artiq/gui/results.py b/artiq/gui/results.py index c7f47214f..9c4c321c8 100644 --- a/artiq/gui/results.py +++ b/artiq/gui/results.py @@ -1,6 +1,7 @@ import asyncio from collections import OrderedDict from functools import partial +import logging from quamash import QtGui, QtCore from pyqtgraph import dockarea @@ -11,6 +12,9 @@ from artiq.gui.tools import DictSyncModel, short_format from artiq.gui.displays import * +logger = logging.getLogger(__name__) + + class ResultsModel(DictSyncModel): def __init__(self, parent, init): DictSyncModel.__init__(self, ["Result", "Value"], @@ -28,6 +32,12 @@ class ResultsModel(DictSyncModel): raise ValueError +def _get_display_type_name(display_cls): + for name, (_, cls) in display_types.items(): + if cls is display_cls: + return name + + class ResultsDock(dockarea.Dock): def __init__(self, dialog_parent, dock_area): dockarea.Dock.__init__(self, "Results", size=(1500, 500)) @@ -110,3 +120,20 @@ class ResultsDock(dockarea.Dock): dsp.sigClosed.connect(on_close) self.dock_area.addDock(dsp) self.dock_area.floatDock(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 + } + return r + + def restore_state(self, state): + for name, desc in state.items(): + try: + self.create_display(desc["ty"], None, name, desc["settings"]) + except: + logger.warning("Failed to create display '%s'", name, + exc_info=True)