From 5b62b2452dcde9c077c41b714ebf1f691edf12bc Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 25 Jul 2015 00:32:18 +0800 Subject: [PATCH] gui: get spinboxes to behave --- artiq/gui/explorer.py | 4 ++-- artiq/gui/scan.py | 10 ++++++---- artiq/gui/tools.py | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/artiq/gui/explorer.py b/artiq/gui/explorer.py index 1d82b2a99..6e9a81334 100644 --- a/artiq/gui/explorer.py +++ b/artiq/gui/explorer.py @@ -7,7 +7,7 @@ from pyqtgraph import LayoutWidget from artiq.protocols.sync_struct import Subscriber 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 @@ -73,7 +73,7 @@ class _NumberEntry(QtGui.QDoubleSpinBox): if procdesc["unit"]: self.setSuffix(" " + procdesc["unit"]) if "default" in procdesc: - self.setValue(procdesc["default"]) + force_spinbox_value(self, procdesc["default"]) def get_argument_value(self): return self.value() diff --git a/artiq/gui/scan.py b/artiq/gui/scan.py index 1ec7c2dcf..2edafa579 100644 --- a/artiq/gui/scan.py +++ b/artiq/gui/scan.py @@ -1,6 +1,8 @@ from quamash import QtGui from pyqtgraph import LayoutWidget +from artiq.gui.tools import force_spinbox_value + class _Range(LayoutWidget): def __init__(self, global_min, global_max, global_step, unit): @@ -33,9 +35,9 @@ class _Range(LayoutWidget): self.addWidget(self.npoints, 0, 5) def set_values(self, min, max, npoints): - self.min.setValue(min) - self.max.setValue(max) - self.npoints.setValue(npoints) + force_spinbox_value(self.min, min) + force_spinbox_value(self.max, max) + force_spinbox_value(self.npoints, npoints) def get_values(self): return { @@ -97,7 +99,7 @@ class ScanController(LayoutWidget): d = procdesc["default"] if d["ty"] == "NoScan": self.noscan.setChecked(True) - self.v_noscan.setValue(d["value"]) + force_spinbox_value(self.v_noscan, d["value"]) elif d["ty"] == "LinearScan": self.linear.setChecked(True) self.v_linear.set_values(d["min"], d["max"], d["step"]) diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index cab4e256d..536790549 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -1,6 +1,14 @@ 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): t = type(v) if t is int or t is float: