From 5574559ac639c0f093e5c25e2f514515214b2de1 Mon Sep 17 00:00:00 2001 From: atse Date: Fri, 26 Jul 2024 17:07:14 +0800 Subject: [PATCH] ctrl_panel: Reformat SpinBox text always if valid The parameter SpinBoxes previously would only update if the interpreted value was changed, missing cases where the text would have changed but the value stays the same, e.g. removing trailing decimal zeros. --- pytec/pytec/gui/view/lockable_unit.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pytec/pytec/gui/view/lockable_unit.py b/pytec/pytec/gui/view/lockable_unit.py index 431c38f..9f7e16b 100644 --- a/pytec/pytec/gui/view/lockable_unit.py +++ b/pytec/pytec/gui/view/lockable_unit.py @@ -91,6 +91,24 @@ class LockableUnitSpinBox(SpinBox): super().setOpts(**opts) + def editingFinishedEvent(self): + # Modified from pyqtgraph.SpinBox.editingFinishedEvent source + + new_text = self.lineEdit().text() + if new_text == self.lastText: + return + try: + val = self.interpret() + except Exception: + return + + if val is False: + return + if val == self.val: + self.updateText() # still update text so that values are reformatted pretty-like + return + self.setValue(val, delaySignal=False) ## allow text update so that values are reformatted pretty-like + def formatText(self, prev=None): """ In addition to pyqtgraph.SpinBox's formatting, incorporate the