diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 357c27e8..93c7f06b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,19 +5,19 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.9 + rev: v0.8.1 hooks: - id: ruff args: [--fix, --unsafe-fixes] - id: ruff-format - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.20.2 + rev: v0.23 hooks: - id: validate-pyproject - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 + rev: v1.13.0 hooks: - id: mypy exclude: tests|examples diff --git a/src/superqt/__init__.py b/src/superqt/__init__.py index ba46f6b5..8d37b63a 100644 --- a/src/superqt/__init__.py +++ b/src/superqt/__init__.py @@ -26,8 +26,6 @@ from .utils import QMessageHandler, ensure_main_thread, ensure_object_thread __all__ = [ - "ensure_main_thread", - "ensure_object_thread", "QCollapsible", "QColorComboBox", "QColormapComboBox", @@ -36,8 +34,8 @@ "QElidingLabel", "QElidingLineEdit", "QEnumComboBox", - "QLabeledDoubleRangeSlider", "QIconifyIcon", + "QLabeledDoubleRangeSlider", "QLabeledDoubleSlider", "QLabeledRangeSlider", "QLabeledSlider", @@ -48,11 +46,13 @@ "QSearchableComboBox", "QSearchableListWidget", "QSearchableTreeWidget", + "ensure_main_thread", + "ensure_object_thread", ] if TYPE_CHECKING: - from .combobox import QColormapComboBox # noqa: TCH004 - from .spinbox._quantity import QQuantity # noqa: TCH004 + from .combobox import QColormapComboBox # noqa: TC004 + from .spinbox._quantity import QQuantity # noqa: TC004 def __getattr__(name: str) -> Any: diff --git a/src/superqt/cmap/__init__.py b/src/superqt/cmap/__init__.py index 458110d2..7aece1c7 100644 --- a/src/superqt/cmap/__init__.py +++ b/src/superqt/cmap/__init__.py @@ -15,9 +15,9 @@ from ._cmap_utils import draw_colormap __all__ = [ - "QColormapItemDelegate", - "draw_colormap", - "QColormapLineEdit", "CmapCatalogComboBox", "QColormapComboBox", + "QColormapItemDelegate", + "QColormapLineEdit", + "draw_colormap", ] diff --git a/src/superqt/cmap/_cmap_utils.py b/src/superqt/cmap/_cmap_utils.py index 840f0df8..219b4a92 100644 --- a/src/superqt/cmap/_cmap_utils.py +++ b/src/superqt/cmap/_cmap_utils.py @@ -121,6 +121,10 @@ def paintEvent(self, event) -> None: painter.setBrush(gradient) painter.drawRect(rect) + # If we created a new Painter, free its resources + if isinstance(painter_or_device, QPaintDevice): + painter.end() + def _draw_checkerboard( painter: QPainter, rect: QRect | QRectF, checker_size: int diff --git a/src/superqt/combobox/__init__.py b/src/superqt/combobox/__init__.py index e8f70121..1041f515 100644 --- a/src/superqt/combobox/__init__.py +++ b/src/superqt/combobox/__init__.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: - from superqt.cmap import QColormapComboBox # noqa: TCH004 + from superqt.cmap import QColormapComboBox # noqa: TC004 def __getattr__(name: str) -> Any: # pragma: no cover diff --git a/src/superqt/elidable/_eliding_label.py b/src/superqt/elidable/_eliding_label.py index 369e193f..8ad2d943 100644 --- a/src/superqt/elidable/_eliding_label.py +++ b/src/superqt/elidable/_eliding_label.py @@ -73,3 +73,10 @@ def sizeHint(self) -> QSize: flags = int(self.alignment() | Qt.TextFlag.TextWordWrap) r = fm.boundingRect(QRect(QPoint(0, 0), self.size()), flags, self._text) return QSize(self.width(), r.height()) + + def minimumSizeHint(self) -> QSize: + # The smallest that self._elidedText can be is just the ellipsis. + fm = QFontMetrics(self.font()) + flags = int(self.alignment() | Qt.TextFlag.TextWordWrap) + r = fm.boundingRect(QRect(QPoint(0, 0), self.size()), flags, "...") + return QSize(r.width(), r.height()) diff --git a/src/superqt/fonticon/__init__.py b/src/superqt/fonticon/__init__.py index e3605582..d80bf37c 100644 --- a/src/superqt/fonticon/__init__.py +++ b/src/superqt/fonticon/__init__.py @@ -1,16 +1,16 @@ from __future__ import annotations __all__ = [ - "addFont", - "Animation", "ENTRY_POINT", - "font", - "icon", + "Animation", "IconFont", "IconFontMeta", "IconOpts", - "pulse", "QIconifyIcon", + "addFont", + "font", + "icon", + "pulse", "setTextIcon", "spin", ] diff --git a/src/superqt/sliders/__init__.py b/src/superqt/sliders/__init__.py index e0e89c5a..e42cedc0 100644 --- a/src/superqt/sliders/__init__.py +++ b/src/superqt/sliders/__init__.py @@ -8,6 +8,7 @@ from ._sliders import QDoubleRangeSlider, QDoubleSlider, QRangeSlider __all__ = [ + "MONTEREY_SLIDER_STYLES_FIX", "QDoubleRangeSlider", "QDoubleSlider", "QLabeledDoubleRangeSlider", @@ -15,5 +16,4 @@ "QLabeledRangeSlider", "QLabeledSlider", "QRangeSlider", - "MONTEREY_SLIDER_STYLES_FIX", ] diff --git a/src/superqt/utils/__init__.py b/src/superqt/utils/__init__.py index 0bf75d57..f3fcfebc 100644 --- a/src/superqt/utils/__init__.py +++ b/src/superqt/utils/__init__.py @@ -1,27 +1,27 @@ from typing import TYPE_CHECKING, Any if TYPE_CHECKING: - from superqt.cmap import draw_colormap # noqa: TCH004 + from superqt.cmap import draw_colormap # noqa: TC004 __all__ = ( "CodeSyntaxHighlight", + "FunctionWorker", + "GeneratorWorker", + "QMessageHandler", + "QSignalDebouncer", + "QSignalThrottler", + "WorkerBase", "create_worker", - "qimage_to_array", "draw_colormap", "ensure_main_thread", "ensure_object_thread", "exceptions_as_dialog", - "FunctionWorker", - "GeneratorWorker", "new_worker_qthread", "qdebounced", - "QMessageHandler", - "QSignalDebouncer", - "QSignalThrottler", + "qimage_to_array", "qthrottled", "signals_blocked", "thread_worker", - "WorkerBase", ) from ._code_syntax_highlight import CodeSyntaxHighlight diff --git a/tests/test_eliding_label.py b/tests/test_eliding_label.py index d3751eb7..2ec9de92 100644 --- a/tests/test_eliding_label.py +++ b/tests/test_eliding_label.py @@ -69,3 +69,14 @@ def test_wrap_text(): assert isinstance(wrap, list) assert all(isinstance(x, str) for x in wrap) assert 9 <= len(wrap) <= 13 + + +def test_minimum_size_hint(): + # The hint should always just be the space needed for "..." + wdg = QElidingLabel() + size_hint = wdg.minimumSizeHint() + # Regardless of what text is contained + wdg.setText(TEXT) + new_hint = wdg.minimumSizeHint() + assert size_hint.width() == new_hint.width() + assert size_hint.height() == new_hint.height() diff --git a/tests/test_throttler.py b/tests/test_throttler.py index b62cbd53..760de89c 100644 --- a/tests/test_throttler.py +++ b/tests/test_throttler.py @@ -125,7 +125,7 @@ def call2(): def test_class_with_slots(qtbot): class A: - __slots__ = ("count", "__weakref__") + __slots__ = ("__weakref__", "count") def __init__(self): self.count = 0