Skip to content

Commit 1758204

Browse files
committedAug 14, 2016
ScientificSpinBox: fix suffix/prefix
1 parent 5f59758 commit 1758204

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed
 

‎artiq/gui/scientific_spinbox.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,24 @@ def textFromValue(self, v):
5454
return t
5555

5656
def valueFromText(self, text):
57-
return round(float(text), self.decimals())
57+
clean = text
58+
if self.prefix():
59+
clean = clean.split(self.prefix(), 1)[-1]
60+
if self.suffix():
61+
clean = clean.rsplit(self.suffix(), 1)[0]
62+
return round(float(clean), self.decimals())
5863

5964
def validate(self, text, pos):
65+
clean = text
66+
if self.prefix():
67+
clean = clean.split(self.prefix(), 1)[-1]
68+
if self.suffix():
69+
clean = clean.rsplit(self.suffix(), 1)[0]
6070
try:
61-
float(text) # faster than matching
71+
float(clean) # faster than matching
6272
return QtGui.QValidator.Acceptable, text, pos
6373
except ValueError:
64-
if re.fullmatch(_float_intermediate, text):
74+
if re.fullmatch(_float_intermediate, clean):
6575
return QtGui.QValidator.Intermediate, text, pos
6676
return QtGui.QValidator.Invalid, text, pos
6777

0 commit comments

Comments
 (0)
Please sign in to comment.