From 003634cadfea33950db374b6373f68a7bbac3b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 29 Jul 2025 12:03:34 -0400 Subject: [PATCH 1/5] Add a block_signals contextmanager to qthelpers --- qtapputils/qthelpers.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/qtapputils/qthelpers.py b/qtapputils/qthelpers.py index 86c40df..efecc50 100644 --- a/qtapputils/qthelpers.py +++ b/qtapputils/qthelpers.py @@ -15,6 +15,7 @@ from qtpy.QtGui import QIcon # ---- Standard imports +from contextlib import contextmanager import sys import platform from math import pi @@ -254,3 +255,14 @@ def get_default_contents_margins() -> list[int, int, int, int]: style.pixelMetric(style.PM_LayoutRightMargin), style.pixelMetric(style.PM_LayoutBottomMargin), ] + + +@contextmanager +def block_signals(widget): + """Temporarily block signals for the given widget.""" + was_blocked = widget.signalsBlocked() + widget.blockSignals(True) + try: + yield + finally: + widget.blockSignals(was_blocked) From 4c6f3f2d67887446ad646d0a1fbe69af479e9bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 29 Jul 2025 12:03:45 -0400 Subject: [PATCH 2/5] Update range.py --- qtapputils/widgets/range.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/qtapputils/widgets/range.py b/qtapputils/widgets/range.py index 03d2ab1..04a27d6 100644 --- a/qtapputils/widgets/range.py +++ b/qtapputils/widgets/range.py @@ -7,11 +7,16 @@ # Licensed under the terms of the MIT License. # ----------------------------------------------------------------------------- + # ---- Third party imports from qtpy.QtCore import Signal, QObject, QLocale, Qt from qtpy.QtGui import QValidator from qtpy.QtWidgets import QDoubleSpinBox, QWidget +# ---- Local imports +from qtapputils.qthelpers import block_signals + + LOCALE = QLocale() @@ -114,10 +119,8 @@ def setValue(self, new_value: float): old_value = self.value() new_value = max(min(new_value, self.maximum()), self.minimum()) - was_blocked = self.signalsBlocked() - self.blockSignals(True) - super().setValue(new_value) - self.blockSignals(was_blocked) + with block_signals(self): + super().setValue(new_value) if self._precise: self._true_value = float(new_value) From 22d52f72b5f63643e7b9beb5779720a0b2cdaad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 29 Jul 2025 14:31:54 -0400 Subject: [PATCH 3/5] Update qthelpers.py --- qtapputils/qthelpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtapputils/qthelpers.py b/qtapputils/qthelpers.py index efecc50..effe1c7 100644 --- a/qtapputils/qthelpers.py +++ b/qtapputils/qthelpers.py @@ -28,7 +28,7 @@ QToolBar) # --- Local imports -from qtapputils.widgets import WaitingSpinner +from qtapputils.widgets.waitingspinner import WaitingSpinner def qbytearray_to_hexstate(qba): From bc8835b8b4efe4c62287ef896358b01b7cab7e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 29 Jul 2025 14:32:21 -0400 Subject: [PATCH 4/5] Minor codestyle change --- qtapputils/widgets/range.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qtapputils/widgets/range.py b/qtapputils/widgets/range.py index 04a27d6..42b2d17 100644 --- a/qtapputils/widgets/range.py +++ b/qtapputils/widgets/range.py @@ -117,13 +117,13 @@ def value(self) -> float: def setValue(self, new_value: float): """Set the value without losing precision due to display rounding.""" old_value = self.value() - new_value = max(min(new_value, self.maximum()), self.minimum()) + new_value = float(max(min(new_value, self.maximum()), self.minimum())) with block_signals(self): super().setValue(new_value) if self._precise: - self._true_value = float(new_value) + self._true_value = new_value if old_value != self.value(): self.sig_value_changed.emit(self.value()) From a14478f848ff747ce5fec123987e30667b802526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 29 Jul 2025 15:03:24 -0400 Subject: [PATCH 5/5] Fix circular import --- qtapputils/qthelpers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qtapputils/qthelpers.py b/qtapputils/qthelpers.py index effe1c7..2b60026 100644 --- a/qtapputils/qthelpers.py +++ b/qtapputils/qthelpers.py @@ -13,6 +13,7 @@ from typing import TYPE_CHECKING, Callable if TYPE_CHECKING: from qtpy.QtGui import QIcon + from qtapputils.widgets.waitingspinner import WaitingSpinner # ---- Standard imports from contextlib import contextmanager @@ -27,9 +28,6 @@ QWidget, QSizePolicy, QToolButton, QApplication, QStyleFactory, QAction, QToolBar) -# --- Local imports -from qtapputils.widgets.waitingspinner import WaitingSpinner - def qbytearray_to_hexstate(qba): """Convert QByteArray object to a str hexstate.""" @@ -174,6 +172,8 @@ def create_waitspinner( spinner : WaitingSpinner The waitspinner created with the specified parameters """ + from qtapputils.widgets.waitingspinner import WaitingSpinner + dot_padding = 1 # To calculate the size of the dots, we need to solve the following