moninj: decouple DAC logic and display

This commit is contained in:
Simon Renblad 2024-04-15 17:39:07 +08:00
parent 6408ae45e0
commit 585d8a4d5b

View File

@ -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("<font size=\"4\">{:.3f}</font><font size=\"2\"> %</font>"
.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")