From 8bde26956ab0b7738e43a467a8c966751c9b1e8e Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Tue, 16 Apr 2024 16:38:56 +0800 Subject: [PATCH] moninj: merge moninj docks --- artiq/dashboard/moninj.py | 44 ++++++++----------------------- artiq/frontend/artiq_dashboard.py | 9 ++----- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/artiq/dashboard/moninj.py b/artiq/dashboard/moninj.py index 24ca3e43d..d015f5384 100644 --- a/artiq/dashboard/moninj.py +++ b/artiq/dashboard/moninj.py @@ -158,9 +158,6 @@ class _TTLHandler: self.widget.level_toggled.connect(self.level_toggled) self.refresh_display() - def sort_key(self): - return self.channel - class _DDSWidget(QtWidgets.QFrame): apply_changes = QtCore.pyqtSignal() @@ -354,9 +351,6 @@ class _DDSHandler: def off_clicked(self): self.dm.dds_channel_toggle(self.dds_name, sw=False) - def sort_key(self): - return (self.bus_channel, self.channel) - class _DACWidget(QtWidgets.QFrame): def __init__(self, channel, title): @@ -407,9 +401,6 @@ class _DACHandler: if self.widget is not None: self.widget.set_value(self.cur_value * 100 / 2**16) - def sort_key(self): - return (self.spi_channel, self.channel) - class Model(DictSyncTreeSepModel): def __init__(self, init): @@ -540,11 +531,8 @@ class _DeviceManager: self.handlers_by_uid = dict() self.dds_sysclk = 0 - self.ttl_cb = lambda: None self.ttl_handlers = dict() - self.dds_cb = lambda: None self.dds_handlers = dict() - self.dac_cb = lambda: None self.dac_handlers = dict() self.channels_cb = lambda: None @@ -598,9 +586,6 @@ class _DeviceManager: raise ValueError if description != self.description: - self.ttl_cb() - self.dds_cb() - self.dac_cb() self.channels_cb() self.description = description @@ -841,16 +826,22 @@ class _DeviceManager: await self.mi_connection.close() -class _MonInjDock(QtWidgets.QDockWidget): - def __init__(self, name): - QtWidgets.QDockWidget.__init__(self, name) - self.setObjectName(name) +class MonInjDock(QtWidgets.QDockWidget): + def __init__(self, schedule_ctl): + QtWidgets.QDockWidget.__init__(self, "MonInj") + self.setObjectName("MonInj") self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) + + self.dm = _DeviceManager(schedule_ctl) + self.dm.channels_cb = lambda: self.set_channels(self.dm.handlers_by_uid) + layout = LayoutWidget() self.setWidget(layout) self._channel_model = Model({}) self.add_channel_dialog = _AddChannelDialog(self, self._channel_model) + self.add_channel_dialog.accepted.connect( + lambda: self.layout_widgets(self.add_channel_dialog.channels)) add_channel_btn = QtWidgets.QToolButton() add_channel_btn.setToolTip("Add channels...") add_channel_btn.setIcon( @@ -867,26 +858,13 @@ class _MonInjDock(QtWidgets.QDockWidget): scroll_area.setWidget(grid_widget) def layout_widgets(self, handlers): - for handler in sorted(handlers, key=lambda h: h.sort_key()): + for handler in handlers: self.grid.addWidget(handler.widget) def set_channels(self, handlers): self._channel_model.clear() self._channel_model.update(handlers) - -class MonInj: - def __init__(self, schedule_ctl): - self.ttl_dock = _MonInjDock("TTL") - self.dds_dock = _MonInjDock("DDS") - self.dac_dock = _MonInjDock("DAC") - - self.dm = _DeviceManager(schedule_ctl) - self.dm.ttl_cb = lambda: self.ttl_dock.layout_widgets(self.dm.ttl_handlers.values()) - self.dm.dds_cb = lambda: self.dds_dock.layout_widgets(self.dm.dds_handlers.values()) - self.dm.dac_cb = lambda: self.dac_dock.layout_widgets(self.dm.dac_handlers.values()) - self.dm.channels_cb = lambda: self.ttl_dock.set_channels(self.dm.handlers_by_uid) - async def stop(self): if self.dm is not None: await self.dm.close() diff --git a/artiq/frontend/artiq_dashboard.py b/artiq/frontend/artiq_dashboard.py index 634f5e29d..37f9e905e 100755 --- a/artiq/frontend/artiq_dashboard.py +++ b/artiq/frontend/artiq_dashboard.py @@ -226,7 +226,7 @@ def main(): smgr.register(d_applets) broadcast_clients["ccb"].notify_cbs.append(d_applets.ccb_notify) - d_ttl_dds = moninj.MonInj(rpc_clients["schedule"]) + d_ttl_dds = moninj.MonInjDock(rpc_clients["schedule"]) atexit_register_coroutine(d_ttl_dds.stop, loop=loop) d_waveform = waveform.WaveformDock( @@ -260,8 +260,7 @@ def main(): # lay out docks right_docks = [ - d_explorer, d_shortcuts, - d_ttl_dds.ttl_dock, d_ttl_dds.dds_dock, d_ttl_dds.dac_dock, + d_explorer, d_shortcuts, d_ttl_dds, d_datasets, d_applets, d_waveform, d_interactive_args ] main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, right_docks[0]) @@ -279,10 +278,6 @@ def main(): smgr.start(loop=loop) atexit_register_coroutine(smgr.stop, loop=loop) - # work around for https://github.com/m-labs/artiq/issues/1307 - d_ttl_dds.ttl_dock.show() - d_ttl_dds.dds_dock.show() - # create first log dock if not already in state d_log0 = logmgr.first_log_dock() if d_log0 is not None: