language, gui: do not automatically insert scale prefixes

This commit is contained in:
Sebastien Bourdeauducq 2015-10-18 00:52:16 +08:00
parent da83212c79
commit b9c1d3ef12
6 changed files with 15 additions and 38 deletions

View File

@ -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"])

View File

@ -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()

View File

@ -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:

View File

@ -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.

View File

@ -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.
"""

View File

@ -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,