From 741dfce38c3affdd0c88ef8a5eaee2559b68e792 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 30 Nov 2015 23:10:12 +0800 Subject: [PATCH] gui/scan: enforce valid sequence input --- artiq/gui/scan.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/artiq/gui/scan.py b/artiq/gui/scan.py index 9ba7ba6d4..5cc9d6fad 100644 --- a/artiq/gui/scan.py +++ b/artiq/gui/scan.py @@ -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()]