forked from M-Labs/artiq
1
0
Fork 0

quickstyle EnumerationValue

This commit is contained in:
Simon Renblad 2024-03-18 13:33:57 +08:00
parent c4323e1179
commit 811bed2a4a
4 changed files with 59 additions and 10 deletions

View File

@ -67,6 +67,8 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
self._arg_to_widgets[name] = widgets
entry = procdesc_to_entry(argument["desc"])(argument)
if argument["desc"].get("quickstyle", False):
entry.quickSubmit.connect(self._submit_quickstyle)
widget_item = QtWidgets.QTreeWidgetItem([name])
if argument["tooltip"]:
widget_item.setToolTip(0, argument["tooltip"])
@ -152,6 +154,16 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
self._groups[name] = group
return group
def _submit_quickstyle(self):
self.about_to_submit()
try:
self.manager.submit(self.expurl)
except:
# May happen when experiment has been removed
# from repository/explist
logger.error("Failed to submit '%s'",
self.expurl, exc_info=True)
def update_argument(self, name, argument):
widgets = self._arg_to_widgets[name]

View File

@ -22,6 +22,8 @@ from artiq.gui.tools import (QDockWidgetCloseDetect, LayoutWidget,
logger = logging.getLogger(__name__)
class EntryArea(QtWidgets.QTreeWidget):
quickSubmit = QtCore.pyqtSignal()
def __init__(self):
QtWidgets.QTreeWidget.__init__(self)
self.setColumnCount(3)
@ -79,6 +81,8 @@ class EntryArea(QtWidgets.QTreeWidget):
entry_class = procdesc_to_entry(argument["desc"])
argument["state"] = entry_class.default_state(argument["desc"])
entry = entry_class(argument)
if desc.get("quickstyle", False):
entry.quickSubmit.connect(self.quickSubmit)
widget_item = QtWidgets.QTreeWidgetItem([key])
if argument["tooltip"]:
widget_item.setToolTip(0, argument["tooltip"])

View File

@ -45,17 +45,48 @@ class BooleanEntry(QtWidgets.QCheckBox):
return procdesc.get("default", False)
class EnumerationEntry(QtWidgets.QComboBox):
class _QuickStyleEnumEntry(QtWidgets.QWidget):
submit = QtCore.pyqtSignal(int)
def __init__(self, choices):
QtWidgets.QWidget.__init__(self)
self.choices = choices
layout = QtWidgets.QHBoxLayout()
self.setLayout(layout)
self.button_group = QtWidgets.QButtonGroup()
for i, choice in enumerate(choices):
button = QtWidgets.QPushButton(choice)
self.button_group.addButton(button)
self.button_group.setId(button, i)
layout.addWidget(button)
self.button_group.idClicked.connect(self.submit)
class EnumerationEntry(QtWidgets.QWidget):
quickSubmit = QtCore.pyqtSignal()
def __init__(self, argument):
QtWidgets.QComboBox.__init__(self)
QtWidgets.QWidget.__init__(self)
disable_scroll_wheel(self)
choices = argument["desc"]["choices"]
self.addItems(choices)
layout = QtWidgets.QGridLayout()
self.setLayout(layout)
procdesc = argument["desc"]
choices = procdesc["choices"]
if procdesc["quickstyle"]:
self.widget = _QuickStyleEnumEntry(choices)
def submit(index):
argument["state"] = choices[index]
self.quickSubmit.emit()
self.widget.submit.connect(submit)
else:
self.widget = QtWidgets.QComboBox()
self.widget.addItems(choices)
idx = choices.index(argument["state"])
self.setCurrentIndex(idx)
self.widget.setCurrentIndex(idx)
def update(index):
argument["state"] = choices[index]
self.currentIndexChanged.connect(update)
self.widget.currentIndexChanged.connect(update)
layout.addWidget(self.widget, 0, 0, 1, 1)
@staticmethod
def state_to_value(state):

View File

@ -83,8 +83,9 @@ class EnumerationValue(_SimpleArgProcessor):
:param choices: A list of string representing the possible values of the
argument.
"""
def __init__(self, choices, default=NoDefault):
def __init__(self, choices, default=NoDefault, quickstyle=False):
self.choices = choices
self.quickstyle = quickstyle
super().__init__(default)
def process(self, x):
@ -95,6 +96,7 @@ class EnumerationValue(_SimpleArgProcessor):
def describe(self):
d = _SimpleArgProcessor.describe(self)
d["choices"] = self.choices
d["quickstyle"] = self.quickstyle
return d