gui: fix spinbox bounds

This commit is contained in:
Sebastien Bourdeauducq 2015-08-25 00:56:19 +08:00
parent e043179120
commit d5f2f5c062
3 changed files with 18 additions and 16 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 DictSyncModel, force_spinbox_value from artiq.gui.tools import DictSyncModel
from artiq.gui.scan import ScanController from artiq.gui.scan import ScanController
@ -79,8 +79,12 @@ class _NumberEntry(QtGui.QDoubleSpinBox):
self.setSingleStep(procdesc["step"]) self.setSingleStep(procdesc["step"])
if procdesc["min"] is not None: if procdesc["min"] is not None:
self.setMinimum(procdesc["min"]) self.setMinimum(procdesc["min"])
else:
self.setMinimum(float("-inf"))
if procdesc["max"] is not None: if procdesc["max"] is not None:
self.setMaximum(procdesc["max"]) self.setMaximum(procdesc["max"])
else:
self.setMaximum(float("inf"))
if procdesc["unit"]: if procdesc["unit"]:
self.setSuffix(" " + procdesc["unit"]) self.setSuffix(" " + procdesc["unit"])
if "default" in procdesc: if "default" in procdesc:
@ -90,7 +94,7 @@ class _NumberEntry(QtGui.QDoubleSpinBox):
return self.value() return self.value()
def set_argument_value(self, value): def set_argument_value(self, value):
force_spinbox_value(self, value) self.setValue(value)
class _StringEntry(QtGui.QLineEdit): class _StringEntry(QtGui.QLineEdit):

View File

@ -1,8 +1,6 @@
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, ndecimals): def __init__(self, global_min, global_max, global_step, unit, ndecimals):
@ -12,8 +10,12 @@ class _Range(LayoutWidget):
spinbox.setDecimals(ndecimals) spinbox.setDecimals(ndecimals)
if global_min is not None: if global_min is not None:
spinbox.setMinimum(global_min) spinbox.setMinimum(global_min)
else:
spinbox.setMinimum(float("-inf"))
if global_max is not None: if global_max is not None:
spinbox.setMaximum(global_max) spinbox.setMaximum(global_max)
else:
spinbox.setMaximum(float("inf"))
if global_step is not None: if global_step is not None:
spinbox.setSingleStep(global_step) spinbox.setSingleStep(global_step)
if unit: if unit:
@ -36,9 +38,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):
force_spinbox_value(self.min, min) self.min.setValue(min)
force_spinbox_value(self.max, max) self.max.setValue(max)
force_spinbox_value(self.npoints, npoints) self.npoints.setValue(npoints)
def get_values(self): def get_values(self):
min = self.min.value() min = self.min.value()
@ -68,8 +70,12 @@ class ScanController(LayoutWidget):
self.v_noscan.setDecimals(ndecimals) self.v_noscan.setDecimals(ndecimals)
if gmin is not None: if gmin is not None:
self.v_noscan.setMinimum(gmin) self.v_noscan.setMinimum(gmin)
else:
self.v_noscan.setMinimum(float("-inf"))
if gmax is not None: if gmax is not None:
self.v_noscan.setMaximum(gmax) self.v_noscan.setMaximum(gmax)
else:
self.v_noscan.setMaximum(float("inf"))
if gstep is not None: if gstep is not None:
self.v_noscan.setSingleStep(gstep) self.v_noscan.setSingleStep(gstep)
if unit: if unit:
@ -135,7 +141,7 @@ class ScanController(LayoutWidget):
def set_argument_value(self, d): def set_argument_value(self, d):
if d["ty"] == "NoScan": if d["ty"] == "NoScan":
self.noscan.setChecked(True) self.noscan.setChecked(True)
force_spinbox_value(self.v_noscan, d["value"]) self.v_noscan.setValue(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["npoints"]) self.v_linear.set_values(d["min"], d["max"], d["npoints"])

View File

@ -37,14 +37,6 @@ def short_format(v):
return r return r
def force_spinbox_value(spinbox, value):
if spinbox.minimum() > value:
spinbox.setMinimum(value)
if spinbox.maximum() < value:
spinbox.setMaximum(value)
spinbox.setValue(value)
class _SyncSubstruct: class _SyncSubstruct:
def __init__(self, update_cb, ref): def __init__(self, update_cb, ref):
self.update_cb = update_cb self.update_cb = update_cb