From c6c768eb777e5c4e6d4f5a98149e694f1f55d08f Mon Sep 17 00:00:00 2001 From: di1ara Date: Wed, 3 Dec 2025 16:50:10 -0500 Subject: [PATCH] fix DpiAwareFont default size calculation --- piker/ui/_style.py | 2 +- pyproject.toml | 3 +++ tests/test_dpi_font.py | 18 ++++++++++++++++++ uv.lock | 6 ++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/test_dpi_font.py diff --git a/piker/ui/_style.py b/piker/ui/_style.py index 196d6fd8..21fb3e74 100644 --- a/piker/ui/_style.py +++ b/piker/ui/_style.py @@ -182,7 +182,7 @@ class DpiAwareFont: # always going to hit that error in range mapping from inches: # float to px size: int. self._font_inches = inches - font_size = math.floor(inches * dpi) + font_size = math.floor(inches * pdpi) log.debug( f"screen:{screen.name()}\n" diff --git a/pyproject.toml b/pyproject.toml index d76f05d5..d5045055 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,6 +77,9 @@ dependencies = [ "trio-typing>=0.10.0", "numba>=0.61.0", "pyvnc", + "pyqt6>=6.8.0", + "pyqtgraph>=0.12.3", + "qdarkstyle>=3.2.3", ] [project.optional-dependencies] diff --git a/tests/test_dpi_font.py b/tests/test_dpi_font.py new file mode 100644 index 00000000..04decfcf --- /dev/null +++ b/tests/test_dpi_font.py @@ -0,0 +1,18 @@ +from PyQt6 import QtGui +from piker.ui._style import DpiAwareFont + +class MockScreen: + def physicalDotsPerInch(self): + return 169 # example HiDPI + def logicalDotsPerInch(self): + return 96 + def name(self): + return "MockScreen" + +# create font instance +font = DpiAwareFont() + +# pass the mock screen to configure_to_dpi +font.configure_to_dpi(screen=MockScreen()) + +print("Computed pixel size:", font.px_size) diff --git a/uv.lock b/uv.lock index 02769ebf..c5cda6b4 100644 --- a/uv.lock +++ b/uv.lock @@ -811,7 +811,10 @@ dependencies = [ { name = "polars-fuzzy-match" }, { name = "pyarrow" }, { name = "pygments" }, + { name = "pyqt6" }, + { name = "pyqtgraph" }, { name = "pyvnc" }, + { name = "qdarkstyle" }, { name = "rapidfuzz" }, { name = "rich" }, { name = "tomli" }, @@ -866,9 +869,12 @@ requires-dist = [ { name = "polars-fuzzy-match", specifier = ">=0.1.5" }, { name = "pyarrow", specifier = ">=18.0.0" }, { name = "pygments", specifier = ">=2.16.1,<3.0.0" }, + { name = "pyqt6", specifier = ">=6.8.0" }, { name = "pyqt6", marker = "extra == 'uis'", specifier = ">=6.7.0,<7.0.0" }, + { name = "pyqtgraph", git = "https://github.com/pikers/pyqtgraph.git" }, { name = "pyqtgraph", marker = "extra == 'uis'", git = "https://github.com/pikers/pyqtgraph.git" }, { name = "pyvnc", git = "https://github.com/regulad/pyvnc.git" }, + { name = "qdarkstyle", specifier = ">=3.2.3" }, { name = "qdarkstyle", marker = "extra == 'uis'", specifier = ">=3.0.2,<4.0.0" }, { name = "rapidfuzz", specifier = ">=3.5.2,<4.0.0" }, { name = "rapidfuzz", marker = "extra == 'uis'", specifier = ">=3.2.0,<4.0.0" },