forked from M-Labs/artiq
1
0
Fork 0

language,gui: support ndecimals in scan and number arguments

This commit is contained in:
Sebastien Bourdeauducq 2015-08-25 00:39:03 +08:00
parent 718de9888b
commit e043179120
5 changed files with 31 additions and 17 deletions

View File

@ -74,6 +74,7 @@ class _EnumerationEntry(QtGui.QComboBox):
class _NumberEntry(QtGui.QDoubleSpinBox): class _NumberEntry(QtGui.QDoubleSpinBox):
def __init__(self, procdesc): def __init__(self, procdesc):
QtGui.QDoubleSpinBox.__init__(self) QtGui.QDoubleSpinBox.__init__(self)
self.setDecimals(procdesc["ndecimals"])
if procdesc["step"] is not None: if procdesc["step"] is not None:
self.setSingleStep(procdesc["step"]) self.setSingleStep(procdesc["step"])
if procdesc["min"] is not None: if procdesc["min"] is not None:

View File

@ -5,10 +5,11 @@ from artiq.gui.tools import force_spinbox_value
class _Range(LayoutWidget): class _Range(LayoutWidget):
def __init__(self, global_min, global_max, global_step, unit): def __init__(self, global_min, global_max, global_step, unit, ndecimals):
LayoutWidget.__init__(self) LayoutWidget.__init__(self)
def apply_properties(spinbox): def apply_properties(spinbox):
spinbox.setDecimals(ndecimals)
if global_min is not None: if global_min is not None:
spinbox.setMinimum(global_min) spinbox.setMinimum(global_min)
if global_max is not None: if global_max is not None:
@ -61,8 +62,10 @@ class ScanController(LayoutWidget):
gmin, gmax = procdesc["global_min"], procdesc["global_max"] gmin, gmax = procdesc["global_min"], procdesc["global_max"]
gstep = procdesc["global_step"] gstep = procdesc["global_step"]
unit = procdesc["unit"] unit = procdesc["unit"]
ndecimals = procdesc["ndecimals"]
self.v_noscan = QtGui.QDoubleSpinBox() self.v_noscan = QtGui.QDoubleSpinBox()
self.v_noscan.setDecimals(ndecimals)
if gmin is not None: if gmin is not None:
self.v_noscan.setMinimum(gmin) self.v_noscan.setMinimum(gmin)
if gmax is not None: if gmax is not None:
@ -76,10 +79,10 @@ class ScanController(LayoutWidget):
self.v_noscan_gr.addWidget(self.v_noscan, 0, 1) self.v_noscan_gr.addWidget(self.v_noscan, 0, 1)
self.stack.addWidget(self.v_noscan_gr) self.stack.addWidget(self.v_noscan_gr)
self.v_linear = _Range(gmin, gmax, gstep, unit) self.v_linear = _Range(gmin, gmax, gstep, unit, ndecimals)
self.stack.addWidget(self.v_linear) self.stack.addWidget(self.v_linear)
self.v_random = _Range(gmin, gmax, gstep, unit) self.v_random = _Range(gmin, gmax, gstep, unit, ndecimals)
self.stack.addWidget(self.v_random) self.stack.addWidget(self.v_random)
self.v_explicit = QtGui.QLineEdit() self.v_explicit = QtGui.QLineEdit()

View File

@ -77,14 +77,16 @@ class NumberValue(_SimpleArgProcessor):
buttons in a UI. buttons in a UI.
:param min: The minimum value of the argument. :param min: The minimum value of the argument.
:param max: The maximum value of the argument. :param max: The maximum value of the argument.
:param ndecimals: The number of decimals a UI should use.
""" """
def __init__(self, default=NoDefault, unit="", step=None, def __init__(self, default=NoDefault, unit="", step=None,
min=None, max=None): min=None, max=None, ndecimals=2):
_SimpleArgProcessor.__init__(self, default) _SimpleArgProcessor.__init__(self, default)
self.unit = unit self.unit = unit
self.step = step self.step = step
self.min = min self.min = min
self.max = max self.max = max
self.ndecimals = ndecimals
def describe(self): def describe(self):
d = _SimpleArgProcessor.describe(self) d = _SimpleArgProcessor.describe(self)
@ -92,6 +94,7 @@ class NumberValue(_SimpleArgProcessor):
d["step"] = self.step d["step"] = self.step
d["min"] = self.min d["min"] = self.min
d["max"] = self.max d["max"] = self.max
d["ndecimals"] = self.ndecimals
return d return d

View File

@ -117,16 +117,19 @@ class Scannable:
:param global_step: The step with which the value should be modified by :param global_step: The step with which the value should be modified by
up/down buttons in a user interface. up/down buttons in a user interface.
:param unit: A string representing the unit of the scanned variable, for user :param unit: A string representing the unit of the scanned variable, for user
interface purposes. interface (UI) purposes.
:param ndecimals: The number of decimals a UI should use.
""" """
def __init__(self, global_min=None, global_max=None, global_step=None, def __init__(self, default=NoDefault, unit="",
unit="", default=NoDefault): global_step=None, global_min=None, global_max=None,
self.global_min = global_min ndecimals=2):
self.global_max = global_max
self.global_step = global_step
self.unit = unit
if default is not NoDefault: if default is not NoDefault:
self.default_value = default self.default_value = default
self.unit = unit
self.global_step = global_step
self.global_min = global_min
self.global_max = global_max
self.ndecimals = ndecimals
def default(self): def default(self):
if not hasattr(self, "default_value"): if not hasattr(self, "default_value"):
@ -143,10 +146,11 @@ class Scannable:
def describe(self): def describe(self):
d = {"ty": "Scannable"} d = {"ty": "Scannable"}
d["global_min"] = self.global_min
d["global_max"] = self.global_max
d["global_step"] = self.global_step
d["unit"] = self.unit
if hasattr(self, "default_value"): if hasattr(self, "default_value"):
d["default"] = self.default_value.describe() d["default"] = self.default_value.describe()
d["unit"] = self.unit
d["global_step"] = self.global_step
d["global_min"] = self.global_min
d["global_max"] = self.global_max
d["ndecimals"] = self.ndecimals
return d return d

View File

@ -35,9 +35,12 @@ class SubComponent2(HasEnvironment):
class ArgumentsDemo(EnvExperiment): class ArgumentsDemo(EnvExperiment):
def build(self): def build(self):
self.attr_argument("free_value", FreeValue(None)) self.attr_argument("free_value", FreeValue(None))
self.attr_argument("number", NumberValue(42, unit="s", step=0.1)) self.attr_argument("number", NumberValue(42, unit="s", step=0.1,
ndecimals=4))
self.attr_argument("string", StringValue("Hello World")) self.attr_argument("string", StringValue("Hello World"))
self.attr_argument("scan", Scannable(global_max=400, default=NoScan(325))) self.attr_argument("scan", Scannable(global_max=400,
default=NoScan(325),
ndecimals=6))
self.attr_argument("boolean", BooleanValue(True), "Group") self.attr_argument("boolean", BooleanValue(True), "Group")
self.attr_argument("enum", EnumerationValue( self.attr_argument("enum", EnumerationValue(
["foo", "bar", "quux"], "foo"), "Group") ["foo", "bar", "quux"], "foo"), "Group")