Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a64766a10d58
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b2f720da67bf
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 1, 2015

  1. Copy the full SHA
    8ad8843 View commit details
  2. gui: better state error handling

    Remains limited by issue pyqtgraph/pyqtgraph#204
    sbourdeauducq committed Aug 1, 2015
    Copy the full SHA
    b2f720d View commit details
Showing with 46 additions and 2 deletions.
  1. +1 −0 artiq/frontend/artiq_gui.py
  2. +27 −0 artiq/gui/results.py
  3. +18 −2 artiq/gui/state.py
1 change: 1 addition & 0 deletions artiq/frontend/artiq_gui.py
Original file line number Diff line number Diff line change
@@ -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()))
27 changes: 27 additions & 0 deletions artiq/gui/results.py
Original file line number Diff line number Diff line change
@@ -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.displays import *


logger = logging.getLogger(__name__)


class ResultsModel(DictSyncModel):
def __init__(self, parent, init):
DictSyncModel.__init__(self, ["Result", "Value"],
@@ -28,6 +32,12 @@ def convert(self, k, v, column):
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 @@ def on_close():
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)
20 changes: 18 additions & 2 deletions artiq/gui/state.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import asyncio
from collections import OrderedDict
import logging

from artiq.tools import TaskObject
from artiq.protocols import pyon


logger = logging.getLogger(__name__)


# support Qt CamelCase naming scheme for save/restore state
def _save_state(obj):
method = getattr(obj, "save_state", None)
@@ -38,6 +42,8 @@ def load(self):
try:
data = pyon.load_file(self.filename)
except FileNotFoundError:
logger.info("State database '%s' not found, using defaults",
self.filename)
return
# The state of one object may depend on the state of another,
# e.g. the display state may create docks that are referenced in
@@ -47,10 +53,20 @@ def load(self):
for name, obj in reversed(list(self.stateful_objects.items())):
state = data.get(name, None)
if state is not None:
_restore_state(obj, state)
try:
_restore_state(obj, state)
except:
logger.warning("Failed to restore state for object '%s'",
name, exc_info=True)

def save(self):
data = {k: _save_state(v) for k, v in self.stateful_objects.items()}
data = dict()
for k, v in self.stateful_objects.items():
try:
data[k] = _save_state(v)
except:
logger.warning("Failed to save state for object '%s'", k,
exc_info=True)
pyon.store_file(self.filename, data)

@asyncio.coroutine