2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 11:18:27 +08:00

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

View File

@ -1,7 +1,7 @@
import logging
from collections import OrderedDict
from quamash import QtGui
from quamash import QtGui, QtCore
from pyqtgraph import LayoutWidget
from artiq.gui.tools import disable_scroll_wheel
@ -90,8 +90,6 @@ class _Range(LayoutWidget):
self.max.valueChanged.connect(update_max)
self.npoints.valueChanged.connect(update_npoints)
# TODO: use QRegExpValidator to prevent invalid input
class _Explicit(LayoutWidget):
def __init__(self, state):
LayoutWidget.__init__(self)
@ -100,6 +98,11 @@ class _Explicit(LayoutWidget):
self.addWidget(QtGui.QLabel("Sequence:"), 0, 0)
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"]]))
def update():
state["sequence"] = [float(x) for x in self.value.text().split()]