From 17582047cb5719e20f5abaa48dff02f94afd5623 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sun, 14 Aug 2016 11:28:06 +0200 Subject: [PATCH] ScientificSpinBox: fix suffix/prefix --- artiq/gui/scientific_spinbox.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/artiq/gui/scientific_spinbox.py b/artiq/gui/scientific_spinbox.py index b6709ee4f..27d415b02 100644 --- a/artiq/gui/scientific_spinbox.py +++ b/artiq/gui/scientific_spinbox.py @@ -54,14 +54,24 @@ class ScientificSpinBox(QtWidgets.QDoubleSpinBox): 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