From 06193ffa30e78785d8972d52e225b83cca55ba1b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Oct 2026 21:52:43 +0000 Subject: [PATCH] feat(quick): add theme aliases used by the positioner box and scan progress ports Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_014KYuz59BEmcx66GwNT3cmL --- bec_widgets/utils/quick/README.md | 7 +++++-- bec_widgets/utils/quick/host.py | 17 ++++++++++++++++- tests/unit_tests/test_ui_kit.py | 5 +++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/bec_widgets/utils/quick/README.md b/bec_widgets/utils/quick/README.md index 6a2dee1a..4115e925 100644 --- a/bec_widgets/utils/quick/README.md +++ b/bec_widgets/utils/quick/README.md @@ -57,8 +57,11 @@ a theme switch. **Aliases for existing ports.** `QmlTheme` also answers to the token names used on the earlier branches, so their QML runs unchanged when they switch to this host: `muted`, `faint`, `text`, `foreground`, `background`, `accent`, `busy`, `ok`, `warn`, `err`, `emergency`, `isDark`, -`busyText`, `okText`, `warnText`, `errText`, `busyTint`, `okTint`, `warnTint`, `errTint`. -New code uses the canonical names. +`busyText`, `okText`, `warnText`, `errText`, `busyTint`, `okTint`, `warnTint`, `errTint`, +`window`, `base`, `button`, `onAccent` and `c` (the raw `bec_qthemes` palette as a map, e.g. +`theme.c.ACCENT_DEFAULT`). New code uses the canonical names. One difference to note: on the +positioner-box branch `accent` meant the selection colour; here it is `ACCENT_DEFAULT`, so use +`primary` where that branch used `accent`. ## Controls diff --git a/bec_widgets/utils/quick/host.py b/bec_widgets/utils/quick/host.py index ad5914fc..daa39f3f 100644 --- a/bec_widgets/utils/quick/host.py +++ b/bec_widgets/utils/quick/host.py @@ -61,7 +61,8 @@ class QmlTheme(QObject): The names used by the first ports are kept as aliases (``muted``, ``faint``, ``text``, ``foreground``, ``background``, ``accent``, ``busy``, ``ok``, ``warn``, ``err``, - ``emergency``, ``isDark``, ``busyText``, ``okTint`` ...), so their QML runs unchanged. + ``emergency``, ``isDark``, ``busyText``, ``okTint``, ``window``, ``base``, ``button``, + ``onAccent`` and the raw palette map ``c``), so their QML runs unchanged. """ changed = Signal() @@ -184,6 +185,20 @@ class QmlTheme(QObject): okTint = _color_property("success_tint") warnTint = _color_property("warning_tint") errTint = _color_property("danger_tint") + window = _color_property("bg") + base = _color_property("field") + button = _color_property("card") + onAccent = _color_property("on_primary") + + @Property("QVariantMap", notify=changed) + def c(self) -> dict: + """The raw ``bec_qthemes`` palette as ``{KEY: "#rrggbb"}``, e.g. ``theme.c.ACCENT_DEFAULT``.""" + theme = app_theme() + colors = dict(getattr(theme, "colors", None) or {}) + return { + key: QColor(value).name() for key, value in colors.items() if QColor(value).isValid() + } + # pylint: enable=invalid-name del _color_property, _metric_property diff --git a/tests/unit_tests/test_ui_kit.py b/tests/unit_tests/test_ui_kit.py index 7c4d26d5..999f99b0 100644 --- a/tests/unit_tests/test_ui_kit.py +++ b/tests/unit_tests/test_ui_kit.py @@ -105,12 +105,17 @@ def test_qml_theme_aliases_match_canonical_names(dark_theme): ("emergency", "danger"), ("errText", "dangerText"), ("okTint", "successTint"), + ("window", "bg"), + ("base", "field"), + ("button", "card"), + ("onAccent", "onPrimary"), ] for alias, canonical in pairs: assert theme.property(alias) == theme.property(canonical), alias assert theme.property("isDark") is True assert theme.property("radiusLarge") == 10 assert theme.toneText("warn") == theme.property("warningText") + assert QColor(theme.property("c")["CARD_BG"]) == theme.property("card") def test_qml_theme_emits_changed_on_theme_switch(qtbot):