From ca4f6d05ffe8dbb89bcd809f5470621f4a475f8c Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 30 Jul 2024 13:31:42 +0800 Subject: [PATCH] =?UTF-8?q?ctrl=5Fpanel:=20Fix=20editing=20fields=20with?= =?UTF-8?q?=20unit=20"=C2=B0C"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A faulty regular expression within PyQtGraph causes any Parameter with a suffix that doesn't begin with an alphanumeric character (as matched with \w) to act abnormally. For instance, entering "100 °C" into the input boxes gets interpreted as 10 °C. Patch the FLOAT_REGEX in PyQtGraph to simply match for any character in the suffix group. --- pytec/pytec/gui/view/lockable_unit.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pytec/pytec/gui/view/lockable_unit.py b/pytec/pytec/gui/view/lockable_unit.py index 78e519f..431c38f 100644 --- a/pytec/pytec/gui/view/lockable_unit.py +++ b/pytec/pytec/gui/view/lockable_unit.py @@ -1,3 +1,5 @@ +import re + from PyQt6.QtCore import QSignalBlocker from PyQt6.QtGui import QValidator @@ -7,6 +9,13 @@ from pyqtgraph.parametertree import registerParameterItemType from pyqtgraph.parametertree.parameterTypes import SimpleParameter, NumericParameterItem +# See https://github.com/pyqtgraph/pyqtgraph/issues/3115 +fn.FLOAT_REGEX = re.compile( + r"(?P[+-]?((((\d+(\.\d*)?)|(\d*\.\d+))([eE][+-]?\d+)?)|((?i:nan)|(inf))))\s*" + + r"((?P[u" + fn.SI_PREFIXES + r"]?)(?P.*))?$" +) + + class LockableUnitSpinBox(SpinBox): """ Extension of PyQtGraph's SpinBox widget.