forked from M-Labs/artiq
1
0
Fork 0

gui/scan: enforce valid sequence input

This commit is contained in:
Sebastien Bourdeauducq 2015-11-30 23:10:12 +08:00
parent a6f3055cd3
commit 741dfce38c
1 changed files with 6 additions and 3 deletions

View File

@ -1,7 +1,7 @@
import logging import logging
from collections import OrderedDict from collections import OrderedDict
from quamash import QtGui from quamash import QtGui, QtCore
from pyqtgraph import LayoutWidget from pyqtgraph import LayoutWidget
from artiq.gui.tools import disable_scroll_wheel from artiq.gui.tools import disable_scroll_wheel
@ -90,8 +90,6 @@ class _Range(LayoutWidget):
self.max.valueChanged.connect(update_max) self.max.valueChanged.connect(update_max)
self.npoints.valueChanged.connect(update_npoints) self.npoints.valueChanged.connect(update_npoints)
# TODO: use QRegExpValidator to prevent invalid input
class _Explicit(LayoutWidget): class _Explicit(LayoutWidget):
def __init__(self, state): def __init__(self, state):
LayoutWidget.__init__(self) LayoutWidget.__init__(self)
@ -100,6 +98,11 @@ class _Explicit(LayoutWidget):
self.addWidget(QtGui.QLabel("Sequence:"), 0, 0) self.addWidget(QtGui.QLabel("Sequence:"), 0, 0)
self.addWidget(self.value, 0, 1) self.addWidget(self.value, 0, 1)
float_regexp = "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"
regexp = "(float)?( +float)* *".replace("float", float_regexp)
self.value.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(regexp),
self.value))
self.value.setText(" ".join([str(x) for x in state["sequence"]])) self.value.setText(" ".join([str(x) for x in state["sequence"]]))
def update(): def update():
state["sequence"] = [float(x) for x in self.value.text().split()] state["sequence"] = [float(x) for x in self.value.text().split()]