From 6f00a4ac55d70b9e37bf1ea0a3a08e6b6bc361f0 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Mon, 15 Apr 2024 16:30:41 +0800 Subject: [PATCH] moninj: create dummy handler classes --- artiq/dashboard/moninj.py | 58 +++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/artiq/dashboard/moninj.py b/artiq/dashboard/moninj.py index 5b6fdc1d2..bb4f93766 100644 --- a/artiq/dashboard/moninj.py +++ b/artiq/dashboard/moninj.py @@ -146,6 +146,14 @@ class _TTLWidget(QtWidgets.QFrame): return self.channel +class _TTLHandler: + def __init__(self, *args, **kw): + self.widget = _TTLWidget(*args, **kw) + + def __getattr__(self, attr): + return getattr(self.widget, attr) + + class _DDSModel: def __init__(self, dds_type, ref_clk, cpld=None, pll=1, clk_div=0): self.cpld = cpld @@ -315,6 +323,14 @@ class _DDSWidget(QtWidgets.QFrame): return (self.bus_channel, self.channel) +class _DDSHandler: + def __init__(self, *args, **kw): + self.widget = _DDSWidget(*args, **kw) + + def __getattr__(self, attr): + return getattr(self.widget, attr) + + class _DACWidget(QtWidgets.QFrame): def __init__(self, dm, spi_channel, channel, title): QtWidgets.QFrame.__init__(self) @@ -352,6 +368,14 @@ class _DACWidget(QtWidgets.QFrame): return (self.spi_channel, self.channel) +class _DACHandler: + def __init__(self, *args, **kw): + self.widget = _DACWidget(*args, **kw) + + def __getattr__(self, attr): + return getattr(self.widget, attr) + + _HandlerDesc = namedtuple("_HandlerDesc", "uid comment cls arguments") @@ -371,14 +395,14 @@ def setup_from_ddb(ddb): continue channel = v["arguments"]["channel"] force_out = v["class"] == "TTLOut" - handler = _HandlerDesc(k, comment, _TTLWidget, (channel, force_out, k)) + handler = _HandlerDesc(k, comment, _TTLHandler, (channel, force_out, k)) description.add(handler) elif (v["module"] == "artiq.coredevice.ad9914" and v["class"] == "AD9914"): bus_channel = v["arguments"]["bus_channel"] channel = v["arguments"]["channel"] dds_sysclk = v["arguments"]["sysclk"] model = _DDSModel(v["class"], dds_sysclk) - handler = _HandlerDesc(k, comment, _DDSWidget, + handler = _HandlerDesc(k, comment, _DDSHandler, (k, bus_channel, channel, model)) description.add(handler) elif (v["module"] == "artiq.coredevice.ad9910" and v["class"] == "AD9910") or \ @@ -393,7 +417,7 @@ def setup_from_ddb(ddb): refclk = ddb[dds_cpld]["arguments"]["refclk"] clk_div = v["arguments"].get("clk_div", 0) model = _DDSModel(v["class"], refclk, dds_cpld, pll, clk_div) - handler = _HandlerDesc(k, comment, _DDSWidget, + handler = _HandlerDesc(k, comment, _DDSHandler, (k, bus_channel, channel, model)) description.add(handler) elif (v["module"] == "artiq.coredevice.ad53xx" and v["class"] == "AD53xx") or \ @@ -404,7 +428,7 @@ def setup_from_ddb(ddb): spi_device = ddb[spi_device] spi_channel = spi_device["arguments"]["channel"] for channel in range(32): - handler = _HandlerDesc((k, channel), comment, _DACWidget, + handler = _HandlerDesc((k, channel), comment, _DACHandler, (spi_channel, channel, k)) description.add(handler) elif v["type"] == "controller" and k == "core_moninj": @@ -452,19 +476,19 @@ class _DeviceManager: handler = self.handlers_by_uid[to_remove.uid] del self.handlers_by_uid[to_remove.uid] - if isinstance(handler, _TTLWidget): + if isinstance(handler, _TTLHandler): self.setup_ttl_monitoring(False, handler.channel) - handler.deleteLater() + handler.widget.deleteLater() del self.ttl_handlers[handler.channel] self.ttl_cb() - elif isinstance(handler, _DDSWidget): + elif isinstance(handler, _DDSHandler): self.setup_dds_monitoring(False, handler.bus_channel, handler.channel) - handler.deleteLater() + handler.widget.deleteLater() del self.dds_handlers[(handler.bus_channel, handler.channel)] self.dds_cb() - elif isinstance(handler, _DACWidget): + elif isinstance(handler, _DACHandler): self.setup_dac_monitoring(False, handler.spi_channel, handler.channel) - handler.deleteLater() + handler.widget.deleteLater() del self.dac_handlers[(handler.spi_channel, handler.channel)] self.dac_cb() else: @@ -473,18 +497,18 @@ class _DeviceManager: for to_add in description - self.description: handler = to_add.cls(self, *to_add.arguments) if to_add.comment is not None: - handler.setToolTip(to_add.comment) + handler.widget.setToolTip(to_add.comment) self.handlers_by_uid[to_add.uid] = handler - if isinstance(handler, _TTLWidget): + if isinstance(handler, _TTLHandler): self.ttl_handlers[handler.channel] = handler self.ttl_cb() self.setup_ttl_monitoring(True, handler.channel) - elif isinstance(handler, _DDSWidget): + elif isinstance(handler, _DDSHandler): self.dds_handlers[(handler.bus_channel, handler.channel)] = handler self.dds_cb() self.setup_dds_monitoring(True, handler.bus_channel, handler.channel) - elif isinstance(handler, _DACWidget): + elif isinstance(handler, _DACHandler): self.dac_handlers[(handler.spi_channel, handler.channel)] = handler self.dac_cb() self.setup_dac_monitoring(True, handler.spi_channel, handler.channel) @@ -735,7 +759,7 @@ class _MonInjDock(QtWidgets.QDockWidget): self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) - def layout_widgets(self, widgets): + def layout_widgets(self, handlers): scroll_area = QtWidgets.QScrollArea() self.setWidget(scroll_area) @@ -743,8 +767,8 @@ class _MonInjDock(QtWidgets.QDockWidget): grid_widget = QtWidgets.QWidget() grid_widget.setLayout(grid) - for widget in sorted(widgets, key=lambda w: w.sort_key()): - grid.addWidget(widget) + for handler in sorted(handlers, key=lambda h: h.sort_key()): + grid.addWidget(handler.widget) scroll_area.setWidgetResizable(True) scroll_area.setWidget(grid_widget)