gui: fix explicit scan input validation

This commit is contained in:
Sebastien Bourdeauducq 2016-05-30 15:45:28 -05:00
parent b57b1ddc57
commit f537562768
1 changed files with 3 additions and 2 deletions

View File

@ -212,14 +212,15 @@ class _ExplicitScan(LayoutWidget):
self.addWidget(QtWidgets.QLabel("Sequence:"), 0, 0) self.addWidget(QtWidgets.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]+)?" float_regexp = r"(([+-]?\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)"
regexp = "(float)?( +float)* *".replace("float", float_regexp) regexp = "(float)?( +float)* *".replace("float", float_regexp)
self.value.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(regexp), self.value.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(regexp),
self.value)) 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(text): def update(text):
state["sequence"] = [float(x) for x in text.split()] if self.value.hasAcceptableInput():
state["sequence"] = [float(x) for x in text.split()]
self.value.textEdited.connect(update) self.value.textEdited.connect(update)