moninj: create dummy handler classes

This commit is contained in:
Simon Renblad 2024-04-15 16:30:41 +08:00
parent 1c506973a3
commit 6f00a4ac55

View File

@ -146,6 +146,14 @@ class _TTLWidget(QtWidgets.QFrame):
return self.channel 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: class _DDSModel:
def __init__(self, dds_type, ref_clk, cpld=None, pll=1, clk_div=0): def __init__(self, dds_type, ref_clk, cpld=None, pll=1, clk_div=0):
self.cpld = cpld self.cpld = cpld
@ -315,6 +323,14 @@ class _DDSWidget(QtWidgets.QFrame):
return (self.bus_channel, self.channel) 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): class _DACWidget(QtWidgets.QFrame):
def __init__(self, dm, spi_channel, channel, title): def __init__(self, dm, spi_channel, channel, title):
QtWidgets.QFrame.__init__(self) QtWidgets.QFrame.__init__(self)
@ -352,6 +368,14 @@ class _DACWidget(QtWidgets.QFrame):
return (self.spi_channel, self.channel) 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") _HandlerDesc = namedtuple("_HandlerDesc", "uid comment cls arguments")
@ -371,14 +395,14 @@ def setup_from_ddb(ddb):
continue continue
channel = v["arguments"]["channel"] channel = v["arguments"]["channel"]
force_out = v["class"] == "TTLOut" 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) description.add(handler)
elif (v["module"] == "artiq.coredevice.ad9914" and v["class"] == "AD9914"): elif (v["module"] == "artiq.coredevice.ad9914" and v["class"] == "AD9914"):
bus_channel = v["arguments"]["bus_channel"] bus_channel = v["arguments"]["bus_channel"]
channel = v["arguments"]["channel"] channel = v["arguments"]["channel"]
dds_sysclk = v["arguments"]["sysclk"] dds_sysclk = v["arguments"]["sysclk"]
model = _DDSModel(v["class"], dds_sysclk) model = _DDSModel(v["class"], dds_sysclk)
handler = _HandlerDesc(k, comment, _DDSWidget, handler = _HandlerDesc(k, comment, _DDSHandler,
(k, bus_channel, channel, model)) (k, bus_channel, channel, model))
description.add(handler) description.add(handler)
elif (v["module"] == "artiq.coredevice.ad9910" and v["class"] == "AD9910") or \ 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"] refclk = ddb[dds_cpld]["arguments"]["refclk"]
clk_div = v["arguments"].get("clk_div", 0) clk_div = v["arguments"].get("clk_div", 0)
model = _DDSModel(v["class"], refclk, dds_cpld, pll, clk_div) 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)) (k, bus_channel, channel, model))
description.add(handler) description.add(handler)
elif (v["module"] == "artiq.coredevice.ad53xx" and v["class"] == "AD53xx") or \ 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_device = ddb[spi_device]
spi_channel = spi_device["arguments"]["channel"] spi_channel = spi_device["arguments"]["channel"]
for channel in range(32): for channel in range(32):
handler = _HandlerDesc((k, channel), comment, _DACWidget, handler = _HandlerDesc((k, channel), comment, _DACHandler,
(spi_channel, channel, k)) (spi_channel, channel, k))
description.add(handler) description.add(handler)
elif v["type"] == "controller" and k == "core_moninj": elif v["type"] == "controller" and k == "core_moninj":
@ -452,19 +476,19 @@ class _DeviceManager:
handler = self.handlers_by_uid[to_remove.uid] handler = self.handlers_by_uid[to_remove.uid]
del 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) self.setup_ttl_monitoring(False, handler.channel)
handler.deleteLater() handler.widget.deleteLater()
del self.ttl_handlers[handler.channel] del self.ttl_handlers[handler.channel]
self.ttl_cb() self.ttl_cb()
elif isinstance(handler, _DDSWidget): elif isinstance(handler, _DDSHandler):
self.setup_dds_monitoring(False, handler.bus_channel, handler.channel) self.setup_dds_monitoring(False, handler.bus_channel, handler.channel)
handler.deleteLater() handler.widget.deleteLater()
del self.dds_handlers[(handler.bus_channel, handler.channel)] del self.dds_handlers[(handler.bus_channel, handler.channel)]
self.dds_cb() self.dds_cb()
elif isinstance(handler, _DACWidget): elif isinstance(handler, _DACHandler):
self.setup_dac_monitoring(False, handler.spi_channel, handler.channel) self.setup_dac_monitoring(False, handler.spi_channel, handler.channel)
handler.deleteLater() handler.widget.deleteLater()
del self.dac_handlers[(handler.spi_channel, handler.channel)] del self.dac_handlers[(handler.spi_channel, handler.channel)]
self.dac_cb() self.dac_cb()
else: else:
@ -473,18 +497,18 @@ class _DeviceManager:
for to_add in description - self.description: for to_add in description - self.description:
handler = to_add.cls(self, *to_add.arguments) handler = to_add.cls(self, *to_add.arguments)
if to_add.comment is not None: 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 self.handlers_by_uid[to_add.uid] = handler
if isinstance(handler, _TTLWidget): if isinstance(handler, _TTLHandler):
self.ttl_handlers[handler.channel] = handler self.ttl_handlers[handler.channel] = handler
self.ttl_cb() self.ttl_cb()
self.setup_ttl_monitoring(True, handler.channel) 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_handlers[(handler.bus_channel, handler.channel)] = handler
self.dds_cb() self.dds_cb()
self.setup_dds_monitoring(True, handler.bus_channel, handler.channel) 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_handlers[(handler.spi_channel, handler.channel)] = handler
self.dac_cb() self.dac_cb()
self.setup_dac_monitoring(True, handler.spi_channel, handler.channel) self.setup_dac_monitoring(True, handler.spi_channel, handler.channel)
@ -735,7 +759,7 @@ class _MonInjDock(QtWidgets.QDockWidget):
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
QtWidgets.QDockWidget.DockWidgetFloatable) QtWidgets.QDockWidget.DockWidgetFloatable)
def layout_widgets(self, widgets): def layout_widgets(self, handlers):
scroll_area = QtWidgets.QScrollArea() scroll_area = QtWidgets.QScrollArea()
self.setWidget(scroll_area) self.setWidget(scroll_area)
@ -743,8 +767,8 @@ class _MonInjDock(QtWidgets.QDockWidget):
grid_widget = QtWidgets.QWidget() grid_widget = QtWidgets.QWidget()
grid_widget.setLayout(grid) grid_widget.setLayout(grid)
for widget in sorted(widgets, key=lambda w: w.sort_key()): for handler in sorted(handlers, key=lambda h: h.sort_key()):
grid.addWidget(widget) grid.addWidget(handler.widget)
scroll_area.setWidgetResizable(True) scroll_area.setWidgetResizable(True)
scroll_area.setWidget(grid_widget) scroll_area.setWidget(grid_widget)