Skip to content

Commit

Permalink
ScientificSpinBox: fix suffix/prefix
Browse files Browse the repository at this point in the history
jordens committed Aug 14, 2016
1 parent 5f59758 commit 1758204
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions artiq/gui/scientific_spinbox.py
Original file line number Diff line number Diff line change
@@ -54,14 +54,24 @@ def textFromValue(self, v):
return t

def valueFromText(self, text):
return round(float(text), self.decimals())
clean = text
if self.prefix():
clean = clean.split(self.prefix(), 1)[-1]
if self.suffix():
clean = clean.rsplit(self.suffix(), 1)[0]
return round(float(clean), self.decimals())

def validate(self, text, pos):
clean = text
if self.prefix():
clean = clean.split(self.prefix(), 1)[-1]
if self.suffix():
clean = clean.rsplit(self.suffix(), 1)[0]
try:
float(text) # faster than matching
float(clean) # faster than matching
return QtGui.QValidator.Acceptable, text, pos
except ValueError:
if re.fullmatch(_float_intermediate, text):
if re.fullmatch(_float_intermediate, clean):
return QtGui.QValidator.Intermediate, text, pos
return QtGui.QValidator.Invalid, text, pos

0 comments on commit 1758204

Please sign in to comment.