Skip to content

Commit

Permalink
Merge branch 'main' into fix-keyerror
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Dec 13, 2024
2 parents 68b49c9 + 2f3113f commit 8e358a2
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/superqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
from .utils import QMessageHandler, ensure_main_thread, ensure_object_thread

__all__ = [
"ensure_main_thread",
"ensure_object_thread",
"QCollapsible",
"QColorComboBox",
"QColormapComboBox",
Expand All @@ -36,8 +34,8 @@
"QElidingLabel",
"QElidingLineEdit",
"QEnumComboBox",
"QLabeledDoubleRangeSlider",
"QIconifyIcon",
"QLabeledDoubleRangeSlider",
"QLabeledDoubleSlider",
"QLabeledRangeSlider",
"QLabeledSlider",
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/superqt/cmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from ._cmap_utils import draw_colormap

__all__ = [
"QColormapItemDelegate",
"draw_colormap",
"QColormapLineEdit",
"CmapCatalogComboBox",
"QColormapComboBox",
"QColormapItemDelegate",
"QColormapLineEdit",
"draw_colormap",
]
4 changes: 4 additions & 0 deletions src/superqt/cmap/_cmap_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/superqt/combobox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/superqt/elidable/_eliding_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
10 changes: 5 additions & 5 deletions src/superqt/fonticon/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
Expand Down
2 changes: 1 addition & 1 deletion src/superqt/sliders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from ._sliders import QDoubleRangeSlider, QDoubleSlider, QRangeSlider

__all__ = [
"MONTEREY_SLIDER_STYLES_FIX",
"QDoubleRangeSlider",
"QDoubleSlider",
"QLabeledDoubleRangeSlider",
"QLabeledDoubleSlider",
"QLabeledRangeSlider",
"QLabeledSlider",
"QRangeSlider",
"MONTEREY_SLIDER_STYLES_FIX",
]
16 changes: 8 additions & 8 deletions src/superqt/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/test_eliding_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/test_throttler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e358a2

Please sign in to comment.