gui: get spinboxes to behave

This commit is contained in:
Sebastien Bourdeauducq 2015-07-25 00:32:18 +08:00
parent 7d81520827
commit 5b62b2452d
3 changed files with 16 additions and 6 deletions

View File

@ -7,7 +7,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 DictSyncModel from artiq.gui.tools import DictSyncModel, force_spinbox_value
from artiq.gui.scan import ScanController from artiq.gui.scan import ScanController
@ -73,7 +73,7 @@ class _NumberEntry(QtGui.QDoubleSpinBox):
if procdesc["unit"]: if procdesc["unit"]:
self.setSuffix(" " + procdesc["unit"]) self.setSuffix(" " + procdesc["unit"])
if "default" in procdesc: if "default" in procdesc:
self.setValue(procdesc["default"]) force_spinbox_value(self, procdesc["default"])
def get_argument_value(self): def get_argument_value(self):
return self.value() return self.value()

View File

@ -1,6 +1,8 @@
from quamash import QtGui from quamash import QtGui
from pyqtgraph import LayoutWidget from pyqtgraph import LayoutWidget
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):
@ -33,9 +35,9 @@ class _Range(LayoutWidget):
self.addWidget(self.npoints, 0, 5) self.addWidget(self.npoints, 0, 5)
def set_values(self, min, max, npoints): def set_values(self, min, max, npoints):
self.min.setValue(min) force_spinbox_value(self.min, min)
self.max.setValue(max) force_spinbox_value(self.max, max)
self.npoints.setValue(npoints) force_spinbox_value(self.npoints, npoints)
def get_values(self): def get_values(self):
return { return {
@ -97,7 +99,7 @@ class ScanController(LayoutWidget):
d = procdesc["default"] d = procdesc["default"]
if d["ty"] == "NoScan": if d["ty"] == "NoScan":
self.noscan.setChecked(True) self.noscan.setChecked(True)
self.v_noscan.setValue(d["value"]) force_spinbox_value(self.v_noscan, d["value"])
elif d["ty"] == "LinearScan": elif d["ty"] == "LinearScan":
self.linear.setChecked(True) self.linear.setChecked(True)
self.v_linear.set_values(d["min"], d["max"], d["step"]) self.v_linear.set_values(d["min"], d["max"], d["step"])

View File

@ -1,6 +1,14 @@
from quamash import QtCore from quamash import QtCore
def force_spinbox_value(spinbox, value):
if spinbox.minimum() > value:
spinbox.setMinimum(value)
if spinbox.maximum() < value:
spinbox.setMaximum(value)
spinbox.setValue(value)
def short_format(v): def short_format(v):
t = type(v) t = type(v)
if t is int or t is float: if t is int or t is float: