mirror of https://github.com/m-labs/artiq.git
gui: use bare QSpinBox for integer NumberEntries. Closes #558
This commit is contained in:
parent
b100770e05
commit
89417a47b2
|
@ -9,7 +9,7 @@ import h5py
|
|||
|
||||
from artiq import __artiq_dir__ as artiq_dir
|
||||
from artiq.gui.tools import LayoutWidget, log_level_to_name, get_open_file_name
|
||||
from artiq.gui.entries import argty_to_entry
|
||||
from artiq.gui.entries import procdesc_to_entry
|
||||
from artiq.protocols import pyon
|
||||
from artiq.master.worker import Worker, log_worker_exception
|
||||
|
||||
|
@ -62,7 +62,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
|
|||
widgets = dict()
|
||||
self._arg_to_widgets[name] = widgets
|
||||
|
||||
entry = argty_to_entry[argument["desc"]["ty"]](argument)
|
||||
entry = procdesc_to_entry(argument["desc"])(argument)
|
||||
widget_item = QtWidgets.QTreeWidgetItem([name])
|
||||
widgets["entry"] = entry
|
||||
widgets["widget_item"] = widget_item
|
||||
|
@ -148,14 +148,14 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
|
|||
argument = self._dock.arguments[name]
|
||||
|
||||
procdesc = arginfo[name][0]
|
||||
state = argty_to_entry[procdesc["ty"]].default_state(procdesc)
|
||||
state = procdesc_to_entry(procdesc).default_state(procdesc)
|
||||
argument["desc"] = procdesc
|
||||
argument["state"] = state
|
||||
|
||||
widgets = self._arg_to_widgets[name]
|
||||
|
||||
widgets["entry"].deleteLater()
|
||||
widgets["entry"] = argty_to_entry[procdesc["ty"]](argument)
|
||||
widgets["entry"] = procdesc_to_entry(procdesc)(argument)
|
||||
widgets["fix_layout"] = LayoutWidget()
|
||||
widgets["fix_layout"].addWidget(widgets["entry"])
|
||||
self.setItemWidget(widgets["widget_item"], 1, widgets["fix_layout"])
|
||||
|
@ -318,7 +318,7 @@ class _ExperimentDock(QtWidgets.QMdiSubWindow):
|
|||
"class_name": class_name,
|
||||
"log_level": self.options["log_level"],
|
||||
"arguments": {
|
||||
name: argty_to_entry[argument["desc"]["ty"]].state_to_value(
|
||||
name: procdesc_to_entry(argument["desc"]).state_to_value(
|
||||
argument["state"])
|
||||
for name, argument in self.arguments.items()},
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ class ExperimentsArea(QtWidgets.QMdiArea):
|
|||
def initialize_submission_arguments(self, arginfo):
|
||||
arguments = OrderedDict()
|
||||
for name, (procdesc, group) in arginfo.items():
|
||||
state = argty_to_entry[procdesc["ty"]].default_state(procdesc)
|
||||
state = procdesc_to_entry(procdesc).default_state(procdesc)
|
||||
arguments[name] = {
|
||||
"desc": procdesc,
|
||||
"group": group,
|
||||
|
|
|
@ -8,7 +8,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||
import h5py
|
||||
|
||||
from artiq.gui.tools import LayoutWidget, log_level_to_name, get_open_file_name
|
||||
from artiq.gui.entries import argty_to_entry, ScanEntry
|
||||
from artiq.gui.entries import procdesc_to_entry, ScanEntry
|
||||
from artiq.protocols import pyon
|
||||
|
||||
|
||||
|
@ -71,7 +71,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
|
|||
widgets = dict()
|
||||
self._arg_to_widgets[name] = widgets
|
||||
|
||||
entry = argty_to_entry[argument["desc"]["ty"]](argument)
|
||||
entry = procdesc_to_entry(argument["desc"])(argument)
|
||||
widget_item = QtWidgets.QTreeWidgetItem([name])
|
||||
widgets["entry"] = entry
|
||||
widgets["widget_item"] = widget_item
|
||||
|
@ -168,7 +168,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
|
|||
argument = self.manager.get_submission_arguments(self.expurl)[name]
|
||||
|
||||
procdesc = arginfo[name][0]
|
||||
state = argty_to_entry[procdesc["ty"]].default_state(procdesc)
|
||||
state = procdesc_to_entry(procdesc).default_state(procdesc)
|
||||
argument["desc"] = procdesc
|
||||
argument["state"] = state
|
||||
|
||||
|
@ -179,7 +179,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
|
|||
widgets = self._arg_to_widgets[name]
|
||||
|
||||
widgets["entry"].deleteLater()
|
||||
widgets["entry"] = argty_to_entry[procdesc["ty"]](argument)
|
||||
widgets["entry"] = procdesc_to_entry(procdesc)(argument)
|
||||
widgets["disable_other_scans"].setVisible(
|
||||
isinstance(widgets["entry"], ScanEntry))
|
||||
widgets["fix_layout"].deleteLater()
|
||||
|
@ -519,7 +519,7 @@ class ExperimentManager:
|
|||
def initialize_submission_arguments(self, expurl, arginfo):
|
||||
arguments = OrderedDict()
|
||||
for name, (procdesc, group) in arginfo.items():
|
||||
state = argty_to_entry[procdesc["ty"]].default_state(procdesc)
|
||||
state = procdesc_to_entry(procdesc).default_state(procdesc)
|
||||
arguments[name] = {
|
||||
"desc": procdesc,
|
||||
"group": group,
|
||||
|
@ -573,7 +573,7 @@ class ExperimentManager:
|
|||
|
||||
argument_values = dict()
|
||||
for name, argument in arguments.items():
|
||||
entry_cls = argty_to_entry[argument["desc"]["ty"]]
|
||||
entry_cls = procdesc_to_entry(argument["desc"])
|
||||
argument_values[name] = entry_cls.state_to_value(argument["state"])
|
||||
|
||||
expid = {
|
||||
|
|
|
@ -69,7 +69,41 @@ class EnumerationEntry(QtWidgets.QComboBox):
|
|||
return procdesc["choices"][0]
|
||||
|
||||
|
||||
class NumberEntry(ScientificSpinBox):
|
||||
class NumberEntryInt(QtWidgets.QSpinBox):
|
||||
def __init__(self, argument):
|
||||
QtWidgets.QSpinBox.__init__(self)
|
||||
disable_scroll_wheel(self)
|
||||
procdesc = argument["desc"]
|
||||
self.setSingleStep(procdesc["step"])
|
||||
if procdesc["min"] is not None:
|
||||
self.setMinimum(procdesc["min"])
|
||||
else:
|
||||
self.setMinimum(-((1 << 31) - 1))
|
||||
if procdesc["max"] is not None:
|
||||
self.setMaximum(procdesc["max"])
|
||||
else:
|
||||
self.setMaximum((1 << 31) - 1)
|
||||
if procdesc["unit"]:
|
||||
self.setSuffix(" " + procdesc["unit"])
|
||||
|
||||
self.setValue(argument["state"])
|
||||
def update(value):
|
||||
argument["state"] = value
|
||||
self.valueChanged.connect(update)
|
||||
|
||||
@staticmethod
|
||||
def state_to_value(state):
|
||||
return state
|
||||
|
||||
@staticmethod
|
||||
def default_state(procdesc):
|
||||
if "default" in procdesc:
|
||||
return procdesc["default"]
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
class NumberEntryFloat(ScientificSpinBox):
|
||||
def __init__(self, argument):
|
||||
ScientificSpinBox.__init__(self)
|
||||
disable_scroll_wheel(self)
|
||||
|
@ -149,6 +183,7 @@ class _NoScan(LayoutWidget):
|
|||
state["repetitions"] = value
|
||||
self.repetitions.valueChanged.connect(update_repetitions)
|
||||
|
||||
|
||||
class _RangeScan(LayoutWidget):
|
||||
def __init__(self, procdesc, state):
|
||||
LayoutWidget.__init__(self)
|
||||
|
@ -331,11 +366,21 @@ class ScanEntry(LayoutWidget):
|
|||
break
|
||||
|
||||
|
||||
argty_to_entry = {
|
||||
def procdesc_to_entry(procdesc):
|
||||
ty = procdesc["ty"]
|
||||
if ty == "NumberValue":
|
||||
is_int = (procdesc["ndecimals"] == 0
|
||||
and int(procdesc["step"]) == procdesc["step"]
|
||||
and procdesc["scale"] == 1)
|
||||
if is_int:
|
||||
return NumberEntryInt
|
||||
else:
|
||||
return NumberEntryFloat
|
||||
else:
|
||||
return {
|
||||
"PYONValue": StringEntry,
|
||||
"BooleanValue": BooleanEntry,
|
||||
"EnumerationValue": EnumerationEntry,
|
||||
"NumberValue": NumberEntry,
|
||||
"StringValue": StringEntry,
|
||||
"Scannable": ScanEntry
|
||||
}
|
||||
}[ty]
|
||||
|
|
Loading…
Reference in New Issue