Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions qtapputils/qthelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
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
import sys
import platform
from math import pi
Expand All @@ -26,9 +28,6 @@
QWidget, QSizePolicy, QToolButton, QApplication, QStyleFactory, QAction,
QToolBar)

# --- Local imports
from qtapputils.widgets import WaitingSpinner


def qbytearray_to_hexstate(qba):
"""Convert QByteArray object to a str hexstate."""
Expand Down Expand Up @@ -173,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
Expand Down Expand Up @@ -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)
15 changes: 9 additions & 6 deletions qtapputils/widgets/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -112,15 +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()))

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)
self._true_value = new_value

if old_value != self.value():
self.sig_value_changed.emit(self.value())
Expand Down