mirror of https://github.com/m-labs/artiq.git
ScientificSpinBox: fix suffix/prefix
This commit is contained in:
parent
5f5975844a
commit
17582047cb
|
@ -54,14 +54,24 @@ class ScientificSpinBox(QtWidgets.QDoubleSpinBox):
|
||||||
return t
|
return t
|
||||||
|
|
||||||
def valueFromText(self, text):
|
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):
|
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:
|
try:
|
||||||
float(text) # faster than matching
|
float(clean) # faster than matching
|
||||||
return QtGui.QValidator.Acceptable, text, pos
|
return QtGui.QValidator.Acceptable, text, pos
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if re.fullmatch(_float_intermediate, text):
|
if re.fullmatch(_float_intermediate, clean):
|
||||||
return QtGui.QValidator.Intermediate, text, pos
|
return QtGui.QValidator.Intermediate, text, pos
|
||||||
return QtGui.QValidator.Invalid, text, pos
|
return QtGui.QValidator.Invalid, text, pos
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue