From b9c1d3ef1298fcb3963310fefc9cee0d3034d36e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 18 Oct 2015 00:52:16 +0800 Subject: [PATCH] language, gui: do not automatically insert scale prefixes --- artiq/gui/explorer.py | 7 +++---- artiq/gui/scan.py | 18 ++++++++---------- artiq/gui/tools.py | 18 ------------------ artiq/language/environment.py | 3 +-- artiq/language/scan.py | 3 +-- examples/master/repository/arguments_demo.py | 4 ++-- 6 files changed, 15 insertions(+), 38 deletions(-) diff --git a/artiq/gui/explorer.py b/artiq/gui/explorer.py index 75ea4f338..76482a94d 100644 --- a/artiq/gui/explorer.py +++ b/artiq/gui/explorer.py @@ -6,7 +6,7 @@ from pyqtgraph import LayoutWidget from artiq.protocols.sync_struct import Subscriber from artiq.protocols import pyon -from artiq.gui.tools import si_prefix, DictSyncModel +from artiq.gui.tools import DictSyncModel from artiq.gui.scan import ScanController @@ -85,9 +85,8 @@ class _NumberEntry(QtGui.QDoubleSpinBox): self.setMaximum(procdesc["max"]/self.scale) else: self.setMaximum(float("inf")) - suffix = si_prefix(self.scale) + procdesc["unit"] - if suffix: - self.setSuffix(" " + suffix) + if procdesc["unit"]: + self.setSuffix(" " + procdesc["unit"]) if "default" in procdesc: self.set_argument_value(procdesc["default"]) diff --git a/artiq/gui/scan.py b/artiq/gui/scan.py index 7ed69ed46..de1d281b2 100644 --- a/artiq/gui/scan.py +++ b/artiq/gui/scan.py @@ -1,11 +1,9 @@ from quamash import QtGui from pyqtgraph import LayoutWidget -from artiq.gui.tools import si_prefix - class _Range(LayoutWidget): - def __init__(self, global_min, global_max, global_step, suffix, scale, ndecimals): + def __init__(self, global_min, global_max, global_step, unit, scale, ndecimals): LayoutWidget.__init__(self) self.scale = scale @@ -21,8 +19,8 @@ class _Range(LayoutWidget): spinbox.setMaximum(float("inf")) if global_step is not None: spinbox.setSingleStep(global_step/self.scale) - if suffix: - spinbox.setSuffix(" " + suffix) + if unit: + spinbox.setSuffix(" " + unit) self.addWidget(QtGui.QLabel("Min:"), 0, 0) self.min = QtGui.QDoubleSpinBox() @@ -68,7 +66,7 @@ class ScanController(LayoutWidget): gmin, gmax = procdesc["global_min"], procdesc["global_max"] gstep = procdesc["global_step"] - suffix = si_prefix(self.scale) + procdesc["unit"] + unit = procdesc["unit"] ndecimals = procdesc["ndecimals"] self.v_noscan = QtGui.QDoubleSpinBox() @@ -82,17 +80,17 @@ class ScanController(LayoutWidget): else: self.v_noscan.setMaximum(float("inf")) self.v_noscan.setSingleStep(gstep/self.scale) - if suffix: - self.v_noscan.setSuffix(" " + suffix) + if unit: + self.v_noscan.setSuffix(" " + unit) self.v_noscan_gr = LayoutWidget() self.v_noscan_gr.addWidget(QtGui.QLabel("Value:"), 0, 0) self.v_noscan_gr.addWidget(self.v_noscan, 0, 1) self.stack.addWidget(self.v_noscan_gr) - self.v_linear = _Range(gmin, gmax, gstep, suffix, self.scale, ndecimals) + self.v_linear = _Range(gmin, gmax, gstep, unit, self.scale, ndecimals) self.stack.addWidget(self.v_linear) - self.v_random = _Range(gmin, gmax, gstep, suffix, self.scale, ndecimals) + self.v_random = _Range(gmin, gmax, gstep, unit, self.scale, ndecimals) self.stack.addWidget(self.v_random) self.v_explicit = QtGui.QLineEdit() diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index 4899b1173..67c7efb42 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -1,22 +1,4 @@ from quamash import QtCore -import numpy as np - - -def si_prefix(scale): - try: - return { - 1e-12: "p", - 1e-9: "n", - 1e-6: "u", - 1e-3: "m", - 1.0: "", - 1e3: "k", - 1e6: "M", - 1e9: "G", - 1e12: "T" - }[scale] - except KeyError: - return "[x{}]".format(scale) class _SyncSubstruct: diff --git a/artiq/language/environment.py b/artiq/language/environment.py index 8c8f11b82..bd7cea725 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -73,8 +73,7 @@ class NumberValue(_SimpleArgProcessor): :param unit: A string representing the unit of the value, for user interface (UI) purposes. - :param scale: The scale of value for UI purposes. The corresponding SI - prefix is shown in front of the unit, and the displayed value is + :param scale: The scale of value for UI purposes. The displayed value is divided by the scale. :param step: The step with which the value should be modified by up/down buttons in a UI. The default is the scale divided by 10. diff --git a/artiq/language/scan.py b/artiq/language/scan.py index 7bc5d5665..86f5ac00b 100644 --- a/artiq/language/scan.py +++ b/artiq/language/scan.py @@ -140,8 +140,7 @@ class Scannable: by 10. :param unit: A string representing the unit of the scanned variable, for user interface (UI) purposes. - :param scale: The scale of value for UI purposes. The corresponding SI - prefix is shown in front of the unit, and the displayed value is + :param scale: The scale of value for UI purposes. The displayed value is divided by the scale. :param ndecimals: The number of decimals a UI should use. """ diff --git a/examples/master/repository/arguments_demo.py b/examples/master/repository/arguments_demo.py index a0114c211..efeb7977a 100644 --- a/examples/master/repository/arguments_demo.py +++ b/examples/master/repository/arguments_demo.py @@ -4,7 +4,7 @@ from artiq import * class SubComponent1(HasEnvironment): def build(self): self.setattr_argument("sc1_scan", Scannable(default=NoScan(3250), - scale=1e3, unit="Hz"), + scale=1e3, unit="kHz"), "Flux capacitor") self.setattr_argument("sc1_enum", EnumerationValue(["1", "2", "3"]), "Flux capacitor") @@ -39,7 +39,7 @@ class ArgumentsDemo(EnvExperiment, LogExperiment): self.setattr_argument("free_value", FreeValue(None)) self.setattr_argument("number", NumberValue(42e-6, - unit="s", scale=1e-6, + unit="us", scale=1e-6, ndecimals=4)) self.setattr_argument("string", StringValue("Hello World")) self.setattr_argument("scan", Scannable(global_max=400,