From 3c4bc4b50c0451c956804466be5de428889e0d58 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/unitful.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pytec/pytec/gui/view/unitful.py b/pytec/pytec/gui/view/unitful.py index 55f20e9..699f4ca 100644 --- a/pytec/pytec/gui/view/unitful.py +++ b/pytec/pytec/gui/view/unitful.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 UnitfulSpinBox(SpinBox): """ Extension of PyQtGraph's SpinBox widget.