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.sync_struct import Subscriber
from artiq.protocols import pyon 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 from artiq.gui.scan import ScanController
@ -85,9 +85,8 @@ class _NumberEntry(QtGui.QDoubleSpinBox):
self.setMaximum(procdesc["max"]/self.scale) self.setMaximum(procdesc["max"]/self.scale)
else: else:
self.setMaximum(float("inf")) self.setMaximum(float("inf"))
suffix = si_prefix(self.scale) + procdesc["unit"] if procdesc["unit"]:
if suffix: self.setSuffix(" " + procdesc["unit"])
self.setSuffix(" " + suffix)
if "default" in procdesc: if "default" in procdesc:
self.set_argument_value(procdesc["default"]) self.set_argument_value(procdesc["default"])

View File

@ -1,11 +1,9 @@
from quamash import QtGui from quamash import QtGui
from pyqtgraph import LayoutWidget from pyqtgraph import LayoutWidget
from artiq.gui.tools import si_prefix
class _Range(LayoutWidget): 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) LayoutWidget.__init__(self)
self.scale = scale self.scale = scale
@ -21,8 +19,8 @@ class _Range(LayoutWidget):
spinbox.setMaximum(float("inf")) spinbox.setMaximum(float("inf"))
if global_step is not None: if global_step is not None:
spinbox.setSingleStep(global_step/self.scale) spinbox.setSingleStep(global_step/self.scale)
if suffix: if unit:
spinbox.setSuffix(" " + suffix) spinbox.setSuffix(" " + unit)
self.addWidget(QtGui.QLabel("Min:"), 0, 0) self.addWidget(QtGui.QLabel("Min:"), 0, 0)
self.min = QtGui.QDoubleSpinBox() self.min = QtGui.QDoubleSpinBox()
@ -68,7 +66,7 @@ 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"]
suffix = si_prefix(self.scale) + procdesc["unit"] unit = procdesc["unit"]
ndecimals = procdesc["ndecimals"] ndecimals = procdesc["ndecimals"]
self.v_noscan = QtGui.QDoubleSpinBox() self.v_noscan = QtGui.QDoubleSpinBox()
@ -82,17 +80,17 @@ class ScanController(LayoutWidget):
else: else:
self.v_noscan.setMaximum(float("inf")) self.v_noscan.setMaximum(float("inf"))
self.v_noscan.setSingleStep(gstep/self.scale) self.v_noscan.setSingleStep(gstep/self.scale)
if suffix: if unit:
self.v_noscan.setSuffix(" " + suffix) self.v_noscan.setSuffix(" " + unit)
self.v_noscan_gr = LayoutWidget() self.v_noscan_gr = LayoutWidget()
self.v_noscan_gr.addWidget(QtGui.QLabel("Value:"), 0, 0) self.v_noscan_gr.addWidget(QtGui.QLabel("Value:"), 0, 0)
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, suffix, self.scale, ndecimals) self.v_linear = _Range(gmin, gmax, gstep, unit, self.scale, ndecimals)
self.stack.addWidget(self.v_linear) 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.stack.addWidget(self.v_random)
self.v_explicit = QtGui.QLineEdit() self.v_explicit = QtGui.QLineEdit()

View File

@ -1,22 +1,4 @@
from quamash import QtCore 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: class _SyncSubstruct:

View File

@ -73,8 +73,7 @@ class NumberValue(_SimpleArgProcessor):
:param unit: A string representing the unit of the value, for user :param unit: A string representing the unit of the value, for user
interface (UI) purposes. interface (UI) purposes.
:param scale: The scale of value for UI purposes. The corresponding SI :param scale: The scale of value for UI purposes. The displayed value is
prefix is shown in front of the unit, and the displayed value is
divided by the scale. divided by the scale.
:param step: The step with which the value should be modified by up/down :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. buttons in a UI. The default is the scale divided by 10.

View File

@ -140,8 +140,7 @@ class Scannable:
by 10. by 10.
: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 (UI) purposes. interface (UI) purposes.
:param scale: The scale of value for UI purposes. The corresponding SI :param scale: The scale of value for UI purposes. The displayed value is
prefix is shown in front of the unit, and the displayed value is
divided by the scale. divided by the scale.
:param ndecimals: The number of decimals a UI should use. :param ndecimals: The number of decimals a UI should use.
""" """

View File

@ -4,7 +4,7 @@ from artiq import *
class SubComponent1(HasEnvironment): class SubComponent1(HasEnvironment):
def build(self): def build(self):
self.setattr_argument("sc1_scan", Scannable(default=NoScan(3250), self.setattr_argument("sc1_scan", Scannable(default=NoScan(3250),
scale=1e3, unit="Hz"), scale=1e3, unit="kHz"),
"Flux capacitor") "Flux capacitor")
self.setattr_argument("sc1_enum", EnumerationValue(["1", "2", "3"]), self.setattr_argument("sc1_enum", EnumerationValue(["1", "2", "3"]),
"Flux capacitor") "Flux capacitor")
@ -39,7 +39,7 @@ class ArgumentsDemo(EnvExperiment, LogExperiment):
self.setattr_argument("free_value", FreeValue(None)) self.setattr_argument("free_value", FreeValue(None))
self.setattr_argument("number", NumberValue(42e-6, self.setattr_argument("number", NumberValue(42e-6,
unit="s", scale=1e-6, unit="us", scale=1e-6,
ndecimals=4)) ndecimals=4))
self.setattr_argument("string", StringValue("Hello World")) self.setattr_argument("string", StringValue("Hello World"))
self.setattr_argument("scan", Scannable(global_max=400, self.setattr_argument("scan", Scannable(global_max=400,