From ef8b09d9bcddc8c7be149a311fc7a5f44046ff52 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 25 Jul 2015 00:36:16 +0800 Subject: [PATCH] gui: add console --- artiq/frontend/artiq_gui.py | 15 ++++++++++++++- artiq/gui/console.py | 21 +++++++++++++++++++++ artiq/gui/parameters.py | 13 ++++++++----- artiq/gui/results.py | 3 +++ 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 artiq/gui/console.py diff --git a/artiq/frontend/artiq_gui.py b/artiq/frontend/artiq_gui.py index f1f63bab4..ad1a19729 100755 --- a/artiq/frontend/artiq_gui.py +++ b/artiq/frontend/artiq_gui.py @@ -18,6 +18,7 @@ from artiq.gui.results import ResultsDock from artiq.gui.parameters import ParametersDock from artiq.gui.schedule import ScheduleDock from artiq.gui.log import LogDock +from artiq.gui.console import ConsoleDock data_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), @@ -109,7 +110,19 @@ def main(): args.server, args.port_notify)) atexit.register(lambda: loop.run_until_complete(d_log.sub_close())) - area.addDock(d_log, "bottom") + pdb = AsyncioClient() + loop.run_until_complete(pdb.connect_rpc( + args.server, args.port_control, "master_pdb")) + atexit.register(lambda: pdb.close_rpc()) + def _get_parameter(k, v): + asyncio.async(pdb.set(k, v)) + d_console = ConsoleDock( + d_params.get_parameter, + _get_parameter, + d_results.get_result) + + area.addDock(d_console, "bottom") + area.addDock(d_log, "above", d_console) area.addDock(d_schedule, "above", d_log) win.show() diff --git a/artiq/gui/console.py b/artiq/gui/console.py new file mode 100644 index 000000000..847a6eac9 --- /dev/null +++ b/artiq/gui/console.py @@ -0,0 +1,21 @@ +from pyqtgraph import console, dockarea + + +_help = """ +The following functions are available: + get_parameter(key) + set_parameter(key, value) [asynchronous update] + get_result(key) [real-time results only] + +""" + +class ConsoleDock(dockarea.Dock): + def __init__(self, get_parameter, set_parameter, get_result): + dockarea.Dock.__init__(self, "Console", size=(1000, 300)) + ns = { + "get_parameter": get_parameter, + "set_parameter": set_parameter, + "get_result": get_result + } + c = console.ConsoleWidget(namespace=ns, text=_help) + self.addWidget(c) diff --git a/artiq/gui/parameters.py b/artiq/gui/parameters.py index 5fbac5866..22f2addbd 100644 --- a/artiq/gui/parameters.py +++ b/artiq/gui/parameters.py @@ -34,7 +34,7 @@ class ParametersDock(dockarea.Dock): self.search = QtGui.QLineEdit() self.search.setPlaceholderText("search...") - self.search.editingFinished.connect(self.search_parameters) + self.search.editingFinished.connect(self._search_parameters) grid.addWidget(self.search, 0, 0) self.table = QtGui.QTableView() @@ -43,7 +43,10 @@ class ParametersDock(dockarea.Dock): QtGui.QHeaderView.ResizeToContents) grid.addWidget(self.table, 1, 0) - def search_parameters(self): + def get_parameter(self, key): + return self.table_model.backing_store[key] + + def _search_parameters(self): model = self.table.model() parentIndex = model.index(0, 0) numRows = model.rowCount(parentIndex) @@ -66,6 +69,6 @@ class ParametersDock(dockarea.Dock): yield from self.subscriber.close() def init_parameters_model(self, init): - table_model = ParametersModel(self.table, init) - self.table.setModel(table_model) - return table_model + self.table_model = ParametersModel(self.table, init) + self.table.setModel(self.table_model) + return self.table_model diff --git a/artiq/gui/results.py b/artiq/gui/results.py index 964856744..c7f47214f 100644 --- a/artiq/gui/results.py +++ b/artiq/gui/results.py @@ -55,6 +55,9 @@ class ResultsDock(dockarea.Dock): self.displays = dict() + def get_result(self, key): + return self.table_model.backing_store[key] + @asyncio.coroutine def sub_connect(self, host, port): self.subscriber = Subscriber("rt_results", self.init_results_model,