From 585d8a4d5b6695d12bad076771b3921d80d8636f Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Mon, 15 Apr 2024 17:39:07 +0800 Subject: [PATCH] moninj: decouple DAC logic and display --- artiq/dashboard/moninj.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/artiq/dashboard/moninj.py b/artiq/dashboard/moninj.py index cd9c2ffbd..c25e95c62 100644 --- a/artiq/dashboard/moninj.py +++ b/artiq/dashboard/moninj.py @@ -345,11 +345,8 @@ class _DDSHandler: class _DACWidget(QtWidgets.QFrame): - def __init__(self, dm, spi_channel, channel, title): + def __init__(self, channel, title): QtWidgets.QFrame.__init__(self) - self.spi_channel = spi_channel - self.channel = channel - self.cur_value = 0 self.setFrameShape(QtWidgets.QFrame.Box) self.setFrameShadow(QtWidgets.QFrame.Raised) @@ -371,22 +368,24 @@ class _DACWidget(QtWidgets.QFrame): grid.setRowStretch(2, 0) grid.setRowStretch(3, 1) - self.refresh_display() - - def refresh_display(self): + def set_value(self, value): self.value.setText("{:.3f} %" - .format(self.cur_value * 100 / 2**16)) - - def sort_key(self): - return (self.spi_channel, self.channel) + .format(value)) class _DACHandler: - def __init__(self, *args, **kw): - self.widget = _DACWidget(*args, **kw) + def __init__(self, dm, spi_channel, channel, title): + self.widget = _DACWidget(channel, title) + self.cur_value = 0 + self.spi_channel = spi_channel + self.channel = channel + self.refresh_display() - def __getattr__(self, attr): - return getattr(self.widget, attr) + def refresh_display(self): + self.widget.set_value(self.cur_value * 100 / 2**16) + + def sort_key(self): + return (self.spi_channel, self.channel) _HandlerDesc = namedtuple("_HandlerDesc", "uid comment cls arguments")