diff --git a/piker/ui/_style.py b/piker/ui/_style.py index b6c47817..893308b0 100644 --- a/piker/ui/_style.py +++ b/piker/ui/_style.py @@ -61,7 +61,7 @@ class DpiAwareFont: ) -> None: self._font_size_calc_key: str = _font_size_key - self._font_size: int | None = None + self._font_size: int|None = None # Read preferred font size from main config file if it exists conf, path = config.load('conf', touch_if_dne=True) @@ -107,7 +107,22 @@ class DpiAwareFont: @property def px_size(self) -> int: - return self._qfont.pixelSize() + size: int = self._qfont.pixelSize() + + # XXX, when no Qt app has been spawned this will always be + # invalid.. + # SO, just return any conf.toml value. + if size == -1: + if (conf_size := self._font_size) is None: + raise ValueError( + f'No valid `{type(_font).__name__}.px_size` set?\n' + f'\n' + f'-> `ui.font_size` is NOT set in `conf.toml`\n' + f'-> no Qt app is active ??\n' + ) + return conf_size + + return size def configure_to_dpi(self, screen: QtGui.QScreen | None = None): ''' @@ -221,6 +236,20 @@ def _config_fonts_to_screen() -> None: _font_small.configure_to_dpi() +def get_fonts() -> tuple[ + DpiAwareFont, + DpiAwareFont, +]: + ''' + Get the singleton font pair (of instances) from which all other + UI/UX should be "scaled around". + + See `DpiAwareFont` for (internal) deats. + + ''' + return _font, _font_small + + # TODO: re-compute font size when main widget switches screens? # https://forum.qt.io/topic/54136/how-do-i-get-the-qscreen-my-widget-is-on-qapplication-desktop-screen-returns-a-qwidget-and-qobject_cast-qscreen-returns-null/3