forked from M-Labs/artiq
moninj: decouple DDS logic and display
This commit is contained in:
parent
6224270396
commit
6408ae45e0
@ -184,14 +184,11 @@ class _DDSModel:
|
|||||||
|
|
||||||
|
|
||||||
class _DDSWidget(QtWidgets.QFrame):
|
class _DDSWidget(QtWidgets.QFrame):
|
||||||
def __init__(self, dm, title, bus_channel=0, channel=0, dds_model=None):
|
apply_changes = QtCore.pyqtSignal()
|
||||||
self.dm = dm
|
off_clicked = QtCore.pyqtSignal()
|
||||||
self.bus_channel = bus_channel
|
set_clicked = QtCore.pyqtSignal()
|
||||||
self.channel = channel
|
|
||||||
self.dds_name = title
|
|
||||||
self.cur_frequency = 0
|
|
||||||
self.dds_model = dds_model
|
|
||||||
|
|
||||||
|
def __init__(self, title, is_urukul):
|
||||||
QtWidgets.QFrame.__init__(self)
|
QtWidgets.QFrame.__init__(self)
|
||||||
|
|
||||||
self.setFrameShape(QtWidgets.QFrame.Box)
|
self.setFrameShape(QtWidgets.QFrame.Box)
|
||||||
@ -253,7 +250,7 @@ class _DDSWidget(QtWidgets.QFrame):
|
|||||||
set_grid.addWidget(set_btn, 0, 1, 1, 1)
|
set_grid.addWidget(set_btn, 0, 1, 1, 1)
|
||||||
|
|
||||||
# for urukuls also allow switching off RF
|
# for urukuls also allow switching off RF
|
||||||
if self.dds_model.is_urukul:
|
if is_urukul:
|
||||||
off_btn = QtWidgets.QToolButton()
|
off_btn = QtWidgets.QToolButton()
|
||||||
off_btn.setText("Off")
|
off_btn.setText("Off")
|
||||||
off_btn.setToolTip("Switch off the output")
|
off_btn.setToolTip("Switch off the output")
|
||||||
@ -280,55 +277,73 @@ class _DDSWidget(QtWidgets.QFrame):
|
|||||||
|
|
||||||
set_btn.clicked.connect(self.set_clicked)
|
set_btn.clicked.connect(self.set_clicked)
|
||||||
apply.clicked.connect(self.apply_changes)
|
apply.clicked.connect(self.apply_changes)
|
||||||
if self.dds_model.is_urukul:
|
if is_urukul:
|
||||||
off_btn.clicked.connect(self.off_clicked)
|
off_btn.clicked.connect(self.off_clicked)
|
||||||
off_btn.setToolTip(textwrap.dedent(
|
off_btn.setToolTip(textwrap.dedent(
|
||||||
"""Note: If TTL RTIO sw for the channel is switched high,
|
"""Note: If TTL RTIO sw for the channel is switched high,
|
||||||
this button will not disable the channel.
|
this button will not disable the channel.
|
||||||
Use the TTL override instead."""))
|
Use the TTL override instead."""))
|
||||||
self.value_edit.returnPressed.connect(lambda: self.apply_changes(None))
|
self.value_edit.returnPressed.connect(self.apply_changes)
|
||||||
self.value_edit.escapePressedConnect(self.cancel_changes)
|
|
||||||
cancel.clicked.connect(self.cancel_changes)
|
|
||||||
|
|
||||||
self.refresh_display()
|
def cancel_changes(cancel):
|
||||||
|
self.set_page(0)
|
||||||
|
self.value_edit.escapePressedConnect(cancel_changes)
|
||||||
|
cancel.clicked.connect(cancel_changes)
|
||||||
|
|
||||||
def set_clicked(self, set):
|
def set_page(self, page):
|
||||||
self.data_stack.setCurrentIndex(1)
|
self.data_stack.setCurrentIndex(page)
|
||||||
self.button_stack.setCurrentIndex(1)
|
self.button_stack.setCurrentIndex(page)
|
||||||
self.value_edit.setText("{:.7f}".format(self.cur_frequency / 1e6))
|
|
||||||
|
def get_value(self):
|
||||||
|
return float(self.value_edit.text())
|
||||||
|
|
||||||
|
def set_edit_value(self, value):
|
||||||
|
self.value_edit.setText("{:.7f}".format(value))
|
||||||
|
|
||||||
|
def set_value(self, value):
|
||||||
|
self.value_label.setText("<font size=\"4\">{:.7f}</font>".format(value))
|
||||||
|
self.set_edit_value(value)
|
||||||
|
|
||||||
|
def start_edit(self):
|
||||||
self.value_edit.setFocus()
|
self.value_edit.setFocus()
|
||||||
self.value_edit.selectAll()
|
self.value_edit.selectAll()
|
||||||
|
|
||||||
def off_clicked(self, set):
|
|
||||||
self.dm.dds_channel_toggle(self.dds_name, self.dds_model, sw=False)
|
|
||||||
|
|
||||||
def apply_changes(self, apply):
|
class _DDSHandler:
|
||||||
self.data_stack.setCurrentIndex(0)
|
def __init__(self, dm, title, bus_channel=0, channel=0, dds_model=None):
|
||||||
self.button_stack.setCurrentIndex(0)
|
self.dm = dm
|
||||||
frequency = float(self.value_edit.text()) * 1e6
|
self.bus_channel = bus_channel
|
||||||
self.dm.dds_set_frequency(self.dds_name, self.dds_model, frequency)
|
self.channel = channel
|
||||||
|
self.cur_frequency = 0
|
||||||
def cancel_changes(self, cancel):
|
self.dds_name = title
|
||||||
self.data_stack.setCurrentIndex(0)
|
self.dds_model = dds_model
|
||||||
self.button_stack.setCurrentIndex(0)
|
self.widget = _DDSWidget(title, dds_model.is_urukul)
|
||||||
|
self.widget.apply_changes.connect(self.apply_changes)
|
||||||
|
self.widget.off_clicked.connect(self.off_clicked)
|
||||||
|
self.widget.set_clicked.connect(self.set_clicked)
|
||||||
|
self.refresh_display()
|
||||||
|
|
||||||
def refresh_display(self):
|
def refresh_display(self):
|
||||||
self.cur_frequency = self.dds_model.cur_frequency
|
self.cur_frequency = self.dds_model.cur_frequency
|
||||||
self.value_label.setText("<font size=\"4\">{:.7f}</font>".format(self.cur_frequency / 1e6))
|
self.widget.set_value(self.cur_frequency / 1e6)
|
||||||
self.value_edit.setText("{:.7f}".format(self.cur_frequency / 1e6))
|
|
||||||
|
def apply_changes(self):
|
||||||
|
self.widget.set_page(0)
|
||||||
|
frequency = self.widget.get_value() * 1e6
|
||||||
|
self.dm.dds_set_frequency(self.dds_name, self.dds_model, frequency)
|
||||||
|
|
||||||
|
def set_clicked(self):
|
||||||
|
self.widget.set_page(1)
|
||||||
|
self.widget.set_edit_value(self.cur_frequency / 1e6)
|
||||||
|
self.widget.start_edit()
|
||||||
|
|
||||||
|
def off_clicked(self):
|
||||||
|
self.dm.dds_channel_toggle(self.dds_name, self.dds_model, sw=False)
|
||||||
|
|
||||||
def sort_key(self):
|
def sort_key(self):
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user