mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-10-28 00:01:27 +01:00
fix(bec_status_box): restyle the QWidget view when the theme changes
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015TeMnCZ9FjLpwiDkPu6K9j
This commit is contained in:
2 files changed
+29
No files matched your search
@@ -271,6 +271,16 @@ class BECStatusBox(BECWidget, CompactPopupWidget):
|
||||
)
|
||||
self.tooltip = f"{self.model.headline}\n{self.model.detail}".strip()
|
||||
|
||||
@SafeSlot(str)
|
||||
def apply_theme(self, theme: str):
|
||||
"""Restyle the QWidget view after a theme change. The QML view follows the theme itself.
|
||||
|
||||
Args:
|
||||
theme (str): The name of the new theme.
|
||||
"""
|
||||
if isinstance(self.view, StatusBoxWidgetView):
|
||||
self.view.apply_theme()
|
||||
|
||||
def cleanup(self):
|
||||
"""Cleanup the BECStatusBox widget."""
|
||||
self.bec_service_status.cleanup()
|
||||
|
||||
@@ -257,3 +257,22 @@ def test_build_rows_order_and_groups():
|
||||
assert [r.group for r in rows] == [CORE_GROUP, CORE_GROUP, OTHER_GROUP, OTHER_GROUP]
|
||||
assert rows[1].tone == "emergency"
|
||||
assert rows[3].status == "NOTCONNECTED"
|
||||
|
||||
|
||||
def test_widget_view_follows_theme(qtbot, mocked_client):
|
||||
from bec_widgets.utils.colors import apply_theme
|
||||
|
||||
box = create_widget(
|
||||
qtbot,
|
||||
BECStatusBox,
|
||||
client=mocked_client,
|
||||
bec_service_status_mixin=mock.MagicMock(),
|
||||
view="widgets",
|
||||
)
|
||||
box.update_service_status(*_all_services())
|
||||
apply_theme("dark")
|
||||
dark = box.view.styleSheet()
|
||||
apply_theme("light")
|
||||
qtbot.waitUntil(lambda: box.view.styleSheet() != dark)
|
||||
apply_theme("dark")
|
||||
qtbot.waitUntil(lambda: box.view.styleSheet() == dark)
|
||||
Reference in new issue
Block a user