diff --git a/artiq/dashboard/experiments.py b/artiq/dashboard/experiments.py index a7db9047b..146fe371e 100644 --- a/artiq/dashboard/experiments.py +++ b/artiq/dashboard/experiments.py @@ -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] diff --git a/artiq/gui/applets.py b/artiq/gui/applets.py index de282c846..048bcff33 100644 --- a/artiq/gui/applets.py +++ b/artiq/gui/applets.py @@ -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"]) diff --git a/artiq/gui/entries.py b/artiq/gui/entries.py index 8b9bf4788..97414e434 100644 --- a/artiq/gui/entries.py +++ b/artiq/gui/entries.py @@ -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) - idx = choices.index(argument["state"]) - self.setCurrentIndex(idx) - def update(index): - argument["state"] = choices[index] - self.currentIndexChanged.connect(update) + 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.widget.setCurrentIndex(idx) + def update(index): + argument["state"] = choices[index] + self.widget.currentIndexChanged.connect(update) + layout.addWidget(self.widget, 0, 0, 1, 1) @staticmethod def state_to_value(state): diff --git a/artiq/language/environment.py b/artiq/language/environment.py index 8b4076a4c..8e6756e24 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -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