forked from M-Labs/artiq
moninj: decouple TTL logic and display
This commit is contained in:
parent
6f00a4ac55
commit
6224270396
@ -26,13 +26,11 @@ class _CancellableLineEdit(QtWidgets.QLineEdit):
|
||||
|
||||
|
||||
class _TTLWidget(QtWidgets.QFrame):
|
||||
def __init__(self, dm, channel, force_out, title):
|
||||
override_toggled = QtCore.pyqtSignal(bool)
|
||||
level_toggled = QtCore.pyqtSignal(bool)
|
||||
|
||||
def __init__(self, title):
|
||||
QtWidgets.QFrame.__init__(self)
|
||||
|
||||
self.channel = channel
|
||||
self.set_mode = dm.ttl_set_mode
|
||||
self.force_out = force_out
|
||||
|
||||
self.setFrameShape(QtWidgets.QFrame.Box)
|
||||
self.setFrameShadow(QtWidgets.QFrame.Raised)
|
||||
|
||||
@ -79,15 +77,28 @@ class _TTLWidget(QtWidgets.QFrame):
|
||||
grid.setRowStretch(3, 0)
|
||||
grid.setRowStretch(4, 1)
|
||||
|
||||
self.programmatic_change = False
|
||||
self.override.clicked.connect(self.override_toggled)
|
||||
self.level.clicked.connect(self.level_toggled)
|
||||
|
||||
self.cur_level = False
|
||||
self.cur_oe = False
|
||||
self.cur_override = False
|
||||
self.cur_override_level = False
|
||||
self.refresh_display()
|
||||
def setValueText(self, override, level):
|
||||
value_s = "1" if level else "0"
|
||||
if override:
|
||||
value_s = "<b>" + value_s + "</b>"
|
||||
color = " color=\"red\""
|
||||
else:
|
||||
color = ""
|
||||
self.value.setText("<font size=\"5\"{}>{}</font>".format(
|
||||
color, value_s))
|
||||
|
||||
def setDirectionText(self, oe):
|
||||
direction = "OUT" if oe else "IN"
|
||||
self.direction.setText("<font size=\"2\">" + direction + "</font>")
|
||||
|
||||
def setButtonsState(self, override, level):
|
||||
self.override.setChecked(override)
|
||||
if override:
|
||||
self.stack.setCurrentIndex(1)
|
||||
self.level.setChecked(level)
|
||||
|
||||
def enterEvent(self, event):
|
||||
self.stack.setCurrentIndex(1)
|
||||
@ -98,11 +109,24 @@ class _TTLWidget(QtWidgets.QFrame):
|
||||
self.stack.setCurrentIndex(0)
|
||||
QtWidgets.QFrame.leaveEvent(self, event)
|
||||
|
||||
|
||||
class _TTLHandler:
|
||||
def __init__(self, dm, channel, force_out, title):
|
||||
self.channel = channel
|
||||
self.force_out = force_out
|
||||
self.set_mode = dm.ttl_set_mode
|
||||
self.cur_level = False
|
||||
self.cur_oe = False
|
||||
self.cur_override = False
|
||||
self.cur_override_level = False
|
||||
self.widget = _TTLWidget(title)
|
||||
self.widget.override_toggled.connect(self.override_toggled)
|
||||
self.widget.level_toggled.connect(self.level_toggled)
|
||||
self.refresh_display()
|
||||
|
||||
def override_toggled(self, override):
|
||||
if self.programmatic_change:
|
||||
return
|
||||
if override:
|
||||
if self.level.isChecked():
|
||||
if self.widget.level.isChecked():
|
||||
self.set_mode(self.channel, "1")
|
||||
else:
|
||||
self.set_mode(self.channel, "0")
|
||||
@ -110,9 +134,7 @@ class _TTLWidget(QtWidgets.QFrame):
|
||||
self.set_mode(self.channel, "exp")
|
||||
|
||||
def level_toggled(self, level):
|
||||
if self.programmatic_change:
|
||||
return
|
||||
if self.override.isChecked():
|
||||
if self.widget.override.isChecked():
|
||||
if level:
|
||||
self.set_mode(self.channel, "1")
|
||||
else:
|
||||
@ -120,40 +142,16 @@ class _TTLWidget(QtWidgets.QFrame):
|
||||
|
||||
def refresh_display(self):
|
||||
level = self.cur_override_level if self.cur_override else self.cur_level
|
||||
value_s = "1" if level else "0"
|
||||
|
||||
if self.cur_override:
|
||||
value_s = "<b>" + value_s + "</b>"
|
||||
color = " color=\"red\""
|
||||
else:
|
||||
color = ""
|
||||
self.value.setText("<font size=\"5\"{}>{}</font>".format(
|
||||
color, value_s))
|
||||
oe = self.cur_oe or self.force_out
|
||||
direction = "OUT" if oe else "IN"
|
||||
self.direction.setText("<font size=\"2\">" + direction + "</font>")
|
||||
|
||||
self.programmatic_change = True
|
||||
try:
|
||||
self.override.setChecked(self.cur_override)
|
||||
if self.cur_override:
|
||||
self.stack.setCurrentIndex(1)
|
||||
self.level.setChecked(self.cur_level)
|
||||
finally:
|
||||
self.programmatic_change = False
|
||||
self.widget.setValueText(self.cur_override, level)
|
||||
self.widget.setDirectionText(oe)
|
||||
with QtCore.QSignalBlocker(self.widget):
|
||||
self.widget.setButtonsState(self.cur_override, self.cur_level)
|
||||
|
||||
def sort_key(self):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user