From 7cdc99fba0035fa54a44c17cb44cb9acfaa69578 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Wed, 26 Jun 2024 21:21:36 +0200 Subject: [PATCH] feat(general_gui): dark/light theme switcher --- .../examples/general_app/general_app.py | 24 ++++++++++++++++--- tests/unit_tests/test_motor_control.py | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bec_widgets/examples/general_app/general_app.py b/bec_widgets/examples/general_app/general_app.py index b2a80042..29521283 100644 --- a/bec_widgets/examples/general_app/general_app.py +++ b/bec_widgets/examples/general_app/general_app.py @@ -2,7 +2,8 @@ import os import sys import qdarktheme -from PySide6.QtWidgets import QStyle +from qtpy.QtGui import QActionGroup +from qtpy.QtWidgets import QStyle from qtpy.QtCore import QSize from qtpy.QtGui import QIcon from qtpy.QtWidgets import QApplication, QMainWindow @@ -24,6 +25,7 @@ class BECGeneralApp(QMainWindow): def ini_ui(self): self._setup_icons() self._hook_menubar_docs() + self._hook_theme_bar() def load_ui(self, ui_file): loader = UILoader(self) @@ -50,7 +52,24 @@ class BECGeneralApp(QMainWindow): self.ui.action_BEC_widgets_docs.setIcon(help_icon) self.ui.action_bug_report.setIcon(bug_icon) - self.ui.central_tab.setTabIcon(0, computer_icon) # Set icon for the first tab + self.ui.central_tab.setTabIcon(0, computer_icon) + + def _hook_theme_bar(self): + # Make actions checkable + self.ui.action_light.setCheckable(True) + self.ui.action_dark.setCheckable(True) + + # Create an action group to make sure only one can be checked at a time + theme_group = QActionGroup(self) + theme_group.addAction(self.ui.action_light) + theme_group.addAction(self.ui.action_dark) + theme_group.setExclusive(True) + + # Connect the actions to the theme change method + self.ui.action_light.triggered.connect(lambda: self.change_theme("light")) + self.ui.action_dark.triggered.connect(lambda: self.change_theme("dark")) + + self.ui.action_dark.trigger() def main(): # pragma: no cover @@ -68,7 +87,6 @@ def main(): # pragma: no cover icon = QIcon() icon.addFile(os.path.join(module_path, "assets", "BEC-Dark.png"), size=QSize(48, 48)) app.setWindowIcon(icon) - qdarktheme.setup_theme("dark") main_window = BECGeneralApp() main_window.show() sys.exit(app.exec_()) diff --git a/tests/unit_tests/test_motor_control.py b/tests/unit_tests/test_motor_control.py index baeb87db..46cb8599 100644 --- a/tests/unit_tests/test_motor_control.py +++ b/tests/unit_tests/test_motor_control.py @@ -3,6 +3,7 @@ from unittest.mock import MagicMock, patch import pytest from bec_lib.devicemanager import DeviceContainer + from bec_widgets.examples.motor_movement.motor_control_compilations import ( MotorControlApp, MotorControlMap, @@ -10,7 +11,6 @@ from bec_widgets.examples.motor_movement.motor_control_compilations import ( MotorControlPanelAbsolute, MotorControlPanelRelative, ) - from bec_widgets.widgets.motor_control.motor_control import MotorActions, MotorThread from bec_widgets.widgets.motor_control.motor_table.motor_table import MotorCoordinateTable from bec_widgets.widgets.motor_control.movement_absolute.movement_absolute import (