From 21e8596d8c373ea3b7c8fafc6caab47399d5d2be Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 14 Jul 2015 17:31:18 +0200 Subject: [PATCH] gui: RT results overview --- artiq/frontend/artiq_gui.py | 9 ++++- artiq/gui/results.py | 68 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 artiq/gui/results.py diff --git a/artiq/frontend/artiq_gui.py b/artiq/frontend/artiq_gui.py index 839121458..9169fb531 100755 --- a/artiq/frontend/artiq_gui.py +++ b/artiq/frontend/artiq_gui.py @@ -14,6 +14,7 @@ from artiq.protocols.file_db import FlatFileDB from artiq.protocols.pc_rpc import AsyncioClient from artiq.gui.explorer import ExplorerDock from artiq.gui.moninj import MonInj +from artiq.gui.results import ResultsDock from artiq.gui.parameters import ParametersDock from artiq.gui.schedule import ScheduleDock from artiq.gui.log import LogDock @@ -70,12 +71,18 @@ def main(): args.server, args.port_notify)) atexit.register(lambda: loop.run_until_complete(d_explorer.sub_close())) + d_results = ResultsDock() + loop.run_until_complete(d_results.sub_connect( + args.server, args.port_notify)) + atexit.register(lambda: loop.run_until_complete(d_results.sub_close())) + d_ttl_dds = MonInj() loop.run_until_complete(d_ttl_dds.start(args.server, args.port_notify)) atexit.register(lambda: loop.run_until_complete(d_ttl_dds.stop())) area.addDock(d_ttl_dds.dds_dock, "top") area.addDock(d_ttl_dds.ttl_dock, "above", d_ttl_dds.dds_dock) - area.addDock(d_explorer, "above", d_ttl_dds.ttl_dock) + area.addDock(d_results, "above", d_ttl_dds.ttl_dock) + area.addDock(d_explorer, "above", d_results) d_params = ParametersDock() area.addDock(d_params, "right", d_explorer) diff --git a/artiq/gui/results.py b/artiq/gui/results.py new file mode 100644 index 000000000..505daaf6e --- /dev/null +++ b/artiq/gui/results.py @@ -0,0 +1,68 @@ +import asyncio + +from quamash import QtGui, QtCore +from pyqtgraph import dockarea +from pyqtgraph import LayoutWidget + +from artiq.protocols.sync_struct import Subscriber +from artiq.gui.tools import DictSyncModel + + +def _fmt_type(v): + t = type(v) + r = t.__name__ + if t is list or t is dict or t is set: + r += " ({})".format(len(v)) + return r + + +class ResultsModel(DictSyncModel): + def __init__(self, parent, init): + DictSyncModel.__init__(self, ["Result", "Type"], + parent, init) + + def sort_key(self, k, v): + return k + + def convert(self, k, v, column): + if column == 0: + return k + elif column == 1: + return _fmt_type(v) + else: + raise ValueError + + +class ResultsDock(dockarea.Dock): + def __init__(self): + dockarea.Dock.__init__(self, "Results", size=(1500, 500)) + + grid = LayoutWidget() + self.addWidget(grid) + + self.table = QtGui.QTableView() + self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) + grid.addWidget(self.table, 0, 0) + + add_display_box = QtGui.QGroupBox("Add display") + grid.addWidget(add_display_box, 0, 1) + display_grid = QtGui.QGridLayout() + add_display_box.setLayout(display_grid) + + for n, name in enumerate(["Number", "XY", "Histogram"]): + btn = QtGui.QPushButton(name) + display_grid.addWidget(btn, n, 0) + + @asyncio.coroutine + def sub_connect(self, host, port): + self.subscriber = Subscriber("rt_results", self.init_results_model) + yield from self.subscriber.connect(host, port) + + @asyncio.coroutine + def sub_close(self): + yield from self.subscriber.close() + + def init_results_model(self, init): + table_model = ResultsModel(self.table, init) + self.table.setModel(table_model) + return table_model