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