forked from M-Labs/artiq
add quickstyle option to EnumerationValue
This commit is contained in:
parent
8e68501081
commit
47716badef
|
@ -28,6 +28,8 @@ class _ArgumentEditor(EntryTreeWidget):
|
||||||
for name, argument in self._dock.arguments.items():
|
for name, argument in self._dock.arguments.items():
|
||||||
self.set_argument(name, argument)
|
self.set_argument(name, argument)
|
||||||
|
|
||||||
|
self.quickStyleClicked.connect(self._dock._run_clicked)
|
||||||
|
|
||||||
recompute_arguments = QtWidgets.QPushButton("Recompute all arguments")
|
recompute_arguments = QtWidgets.QPushButton("Recompute all arguments")
|
||||||
recompute_arguments.setIcon(
|
recompute_arguments.setIcon(
|
||||||
QtWidgets.QApplication.style().standardIcon(
|
QtWidgets.QApplication.style().standardIcon(
|
||||||
|
|
|
@ -39,6 +39,8 @@ class _ArgumentEditor(EntryTreeWidget):
|
||||||
for name, argument in arguments.items():
|
for name, argument in arguments.items():
|
||||||
self.set_argument(name, argument)
|
self.set_argument(name, argument)
|
||||||
|
|
||||||
|
self.quickStyleClicked.connect(dock.submit_clicked)
|
||||||
|
|
||||||
recompute_arguments = QtWidgets.QPushButton("Recompute all arguments")
|
recompute_arguments = QtWidgets.QPushButton("Recompute all arguments")
|
||||||
recompute_arguments.setIcon(
|
recompute_arguments.setIcon(
|
||||||
QtWidgets.QApplication.style().standardIcon(
|
QtWidgets.QApplication.style().standardIcon(
|
||||||
|
|
|
@ -13,6 +13,8 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class EntryTreeWidget(QtWidgets.QTreeWidget):
|
class EntryTreeWidget(QtWidgets.QTreeWidget):
|
||||||
|
quickStyleClicked = QtCore.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtWidgets.QTreeWidget.__init__(self)
|
QtWidgets.QTreeWidget.__init__(self)
|
||||||
self.setColumnCount(3)
|
self.setColumnCount(3)
|
||||||
|
@ -53,6 +55,8 @@ class EntryTreeWidget(QtWidgets.QTreeWidget):
|
||||||
entry_class = procdesc_to_entry(argument["desc"])
|
entry_class = procdesc_to_entry(argument["desc"])
|
||||||
argument["state"] = entry_class.default_state(argument["desc"])
|
argument["state"] = entry_class.default_state(argument["desc"])
|
||||||
entry = entry_class(argument)
|
entry = entry_class(argument)
|
||||||
|
if argument["desc"].get("quickstyle"):
|
||||||
|
entry.quickStyleClicked.connect(self.quickStyleClicked)
|
||||||
widget_item = QtWidgets.QTreeWidgetItem([key])
|
widget_item = QtWidgets.QTreeWidgetItem([key])
|
||||||
if argument["tooltip"]:
|
if argument["tooltip"]:
|
||||||
widget_item.setToolTip(0, argument["tooltip"])
|
widget_item.setToolTip(0, argument["tooltip"])
|
||||||
|
@ -193,17 +197,38 @@ class BooleanEntry(QtWidgets.QCheckBox):
|
||||||
return procdesc.get("default", False)
|
return procdesc.get("default", False)
|
||||||
|
|
||||||
|
|
||||||
class EnumerationEntry(QtWidgets.QComboBox):
|
class EnumerationEntry(QtWidgets.QWidget):
|
||||||
|
quickStyleClicked = QtCore.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, argument):
|
def __init__(self, argument):
|
||||||
QtWidgets.QComboBox.__init__(self)
|
QtWidgets.QWidget.__init__(self)
|
||||||
disable_scroll_wheel(self)
|
disable_scroll_wheel(self)
|
||||||
choices = argument["desc"]["choices"]
|
layout = QtWidgets.QHBoxLayout()
|
||||||
self.addItems(choices)
|
self.setLayout(layout)
|
||||||
idx = choices.index(argument["state"])
|
procdesc = argument["desc"]
|
||||||
self.setCurrentIndex(idx)
|
choices = procdesc["choices"]
|
||||||
def update(index):
|
if procdesc["quickstyle"]:
|
||||||
argument["state"] = choices[index]
|
self.btn_group = QtWidgets.QButtonGroup()
|
||||||
self.currentIndexChanged.connect(update)
|
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
|
@staticmethod
|
||||||
def state_to_value(state):
|
def state_to_value(state):
|
||||||
|
|
|
@ -90,8 +90,9 @@ class EnumerationValue(_SimpleArgProcessor):
|
||||||
:param choices: A list of string representing the possible values of the
|
:param choices: A list of string representing the possible values of the
|
||||||
argument.
|
argument.
|
||||||
"""
|
"""
|
||||||
def __init__(self, choices, default=NoDefault):
|
def __init__(self, choices, default=NoDefault, quickstyle=False):
|
||||||
self.choices = choices
|
self.choices = choices
|
||||||
|
self.quickstyle = quickstyle
|
||||||
super().__init__(default)
|
super().__init__(default)
|
||||||
|
|
||||||
def process(self, x):
|
def process(self, x):
|
||||||
|
@ -102,6 +103,7 @@ class EnumerationValue(_SimpleArgProcessor):
|
||||||
def describe(self):
|
def describe(self):
|
||||||
d = _SimpleArgProcessor.describe(self)
|
d = _SimpleArgProcessor.describe(self)
|
||||||
d["choices"] = self.choices
|
d["choices"] = self.choices
|
||||||
|
d["quickstyle"] = self.quickstyle
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue