From e04317912068797364b9bacf3ab75f94706f99aa Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 25 Aug 2015 00:39:03 +0800 Subject: [PATCH] language,gui: support ndecimals in scan and number arguments --- artiq/gui/explorer.py | 1 + artiq/gui/scan.py | 9 ++++--- artiq/language/environment.py | 5 +++- artiq/language/scan.py | 26 +++++++++++--------- examples/master/repository/arguments_demo.py | 7 ++++-- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/artiq/gui/explorer.py b/artiq/gui/explorer.py index 81b491d52..c4f5ea680 100644 --- a/artiq/gui/explorer.py +++ b/artiq/gui/explorer.py @@ -74,6 +74,7 @@ class _EnumerationEntry(QtGui.QComboBox): class _NumberEntry(QtGui.QDoubleSpinBox): def __init__(self, procdesc): QtGui.QDoubleSpinBox.__init__(self) + self.setDecimals(procdesc["ndecimals"]) if procdesc["step"] is not None: self.setSingleStep(procdesc["step"]) if procdesc["min"] is not None: diff --git a/artiq/gui/scan.py b/artiq/gui/scan.py index ea34cf8d3..65d81ae52 100644 --- a/artiq/gui/scan.py +++ b/artiq/gui/scan.py @@ -5,10 +5,11 @@ from artiq.gui.tools import force_spinbox_value 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) def apply_properties(spinbox): + spinbox.setDecimals(ndecimals) if global_min is not None: spinbox.setMinimum(global_min) if global_max is not None: @@ -61,8 +62,10 @@ class ScanController(LayoutWidget): gmin, gmax = procdesc["global_min"], procdesc["global_max"] gstep = procdesc["global_step"] unit = procdesc["unit"] + ndecimals = procdesc["ndecimals"] self.v_noscan = QtGui.QDoubleSpinBox() + self.v_noscan.setDecimals(ndecimals) if gmin is not None: self.v_noscan.setMinimum(gmin) if gmax is not None: @@ -76,10 +79,10 @@ class ScanController(LayoutWidget): self.v_noscan_gr.addWidget(self.v_noscan, 0, 1) 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.v_random = _Range(gmin, gmax, gstep, unit) + self.v_random = _Range(gmin, gmax, gstep, unit, ndecimals) self.stack.addWidget(self.v_random) self.v_explicit = QtGui.QLineEdit() diff --git a/artiq/language/environment.py b/artiq/language/environment.py index 8ecfa0499..fa3f30849 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -77,14 +77,16 @@ class NumberValue(_SimpleArgProcessor): buttons in a UI. :param min: The minimum 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, - min=None, max=None): + min=None, max=None, ndecimals=2): _SimpleArgProcessor.__init__(self, default) self.unit = unit self.step = step self.min = min self.max = max + self.ndecimals = ndecimals def describe(self): d = _SimpleArgProcessor.describe(self) @@ -92,6 +94,7 @@ class NumberValue(_SimpleArgProcessor): d["step"] = self.step d["min"] = self.min d["max"] = self.max + d["ndecimals"] = self.ndecimals return d diff --git a/artiq/language/scan.py b/artiq/language/scan.py index 33e98eb4e..fe22c5a4f 100644 --- a/artiq/language/scan.py +++ b/artiq/language/scan.py @@ -117,16 +117,19 @@ class Scannable: :param global_step: The step with which the value should be modified by up/down buttons in a user interface. :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, - unit="", default=NoDefault): - self.global_min = global_min - self.global_max = global_max - self.global_step = global_step - self.unit = unit + def __init__(self, default=NoDefault, unit="", + global_step=None, global_min=None, global_max=None, + ndecimals=2): if default is not NoDefault: 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): if not hasattr(self, "default_value"): @@ -143,10 +146,11 @@ class Scannable: def describe(self): 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"): 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 diff --git a/examples/master/repository/arguments_demo.py b/examples/master/repository/arguments_demo.py index d956071b3..08ef43ba2 100644 --- a/examples/master/repository/arguments_demo.py +++ b/examples/master/repository/arguments_demo.py @@ -35,9 +35,12 @@ class SubComponent2(HasEnvironment): class ArgumentsDemo(EnvExperiment): def build(self): 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("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("enum", EnumerationValue( ["foo", "bar", "quux"], "foo"), "Group")