From 47716badef7ed6839fc57732078aca794f077d62 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Mon, 25 Mar 2024 14:37:47 +0800 Subject: [PATCH] add quickstyle option to EnumerationValue --- artiq/browser/experiments.py | 2 ++ artiq/dashboard/experiments.py | 2 ++ artiq/gui/entries.py | 43 +++++++++++++++++++++++++++------- artiq/language/environment.py | 4 +++- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/artiq/browser/experiments.py b/artiq/browser/experiments.py index 7bacba15b..7c2267937 100644 --- a/artiq/browser/experiments.py +++ b/artiq/browser/experiments.py @@ -28,6 +28,8 @@ class _ArgumentEditor(EntryTreeWidget): for name, argument in self._dock.arguments.items(): self.set_argument(name, argument) + self.quickStyleClicked.connect(self._dock._run_clicked) + recompute_arguments = QtWidgets.QPushButton("Recompute all arguments") recompute_arguments.setIcon( QtWidgets.QApplication.style().standardIcon( diff --git a/artiq/dashboard/experiments.py b/artiq/dashboard/experiments.py index c5409624c..0defaa103 100644 --- a/artiq/dashboard/experiments.py +++ b/artiq/dashboard/experiments.py @@ -39,6 +39,8 @@ class _ArgumentEditor(EntryTreeWidget): for name, argument in arguments.items(): self.set_argument(name, argument) + self.quickStyleClicked.connect(dock.submit_clicked) + recompute_arguments = QtWidgets.QPushButton("Recompute all arguments") recompute_arguments.setIcon( QtWidgets.QApplication.style().standardIcon( diff --git a/artiq/gui/entries.py b/artiq/gui/entries.py index 3eea8b880..dd7231331 100644 --- a/artiq/gui/entries.py +++ b/artiq/gui/entries.py @@ -13,6 +13,8 @@ logger = logging.getLogger(__name__) class EntryTreeWidget(QtWidgets.QTreeWidget): + quickStyleClicked = QtCore.pyqtSignal() + def __init__(self): QtWidgets.QTreeWidget.__init__(self) self.setColumnCount(3) @@ -53,6 +55,8 @@ class EntryTreeWidget(QtWidgets.QTreeWidget): entry_class = procdesc_to_entry(argument["desc"]) argument["state"] = entry_class.default_state(argument["desc"]) entry = entry_class(argument) + if argument["desc"].get("quickstyle"): + entry.quickStyleClicked.connect(self.quickStyleClicked) widget_item = QtWidgets.QTreeWidgetItem([key]) if argument["tooltip"]: widget_item.setToolTip(0, argument["tooltip"]) @@ -193,17 +197,38 @@ class BooleanEntry(QtWidgets.QCheckBox): return procdesc.get("default", False) -class EnumerationEntry(QtWidgets.QComboBox): +class EnumerationEntry(QtWidgets.QWidget): + quickStyleClicked = 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.QHBoxLayout() + self.setLayout(layout) + procdesc = argument["desc"] + choices = procdesc["choices"] + if procdesc["quickstyle"]: + self.btn_group = QtWidgets.QButtonGroup() + for i, choice in enumerate(choices): + button = QtWidgets.QPushButton(choice) + self.btn_group.addButton(button) + self.btn_group.setId(button, i) + layout.addWidget(button) + + def submit(index): + argument["state"] = choices[index] + self.quickStyleClicked.emit() + self.btn_group.idClicked.connect(submit) + else: + self.combo_box = QtWidgets.QComboBox() + self.combo_box.addItems(choices) + idx = choices.index(argument["state"]) + self.combo_box.setCurrentIndex(idx) + layout.addWidget(self.combo_box) + + def update(index): + argument["state"] = choices[index] + self.combo_box.currentIndexChanged.connect(update) @staticmethod def state_to_value(state): diff --git a/artiq/language/environment.py b/artiq/language/environment.py index fe5753184..edb8865b1 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -90,8 +90,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): @@ -102,6 +103,7 @@ class EnumerationValue(_SimpleArgProcessor): def describe(self): d = _SimpleArgProcessor.describe(self) d["choices"] = self.choices + d["quickstyle"] = self.quickstyle return d