diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 7211d512..477468b7 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -2292,9 +2292,10 @@ class BECWaveformWidget(RPCBase): class DarkModeButton(RPCBase): @rpc_call - def set_dark_mode_enabled(self) -> None: + def toggle_dark_mode(self) -> None: """ - None + Toggle the dark mode state. This will change the theme of the entire + application to dark or light mode. """ diff --git a/bec_widgets/widgets/dark_mode_button/dark_mode_button.py b/bec_widgets/widgets/dark_mode_button/dark_mode_button.py index d433f204..5677a0b2 100644 --- a/bec_widgets/widgets/dark_mode_button/dark_mode_button.py +++ b/bec_widgets/widgets/dark_mode_button/dark_mode_button.py @@ -7,7 +7,7 @@ from bec_widgets.utils.colors import set_theme class DarkModeButton(BECWidget, QWidget): - USER_ACCESS = ["set_dark_mode_enabled"] + USER_ACCESS = ["toggle_dark_mode"] def __init__( self, parent: QWidget | None = None, client=None, gui_id: str | None = None @@ -24,7 +24,7 @@ class DarkModeButton(BECWidget, QWidget): icon = material_icon("dark_mode", size=(20, 20), convert_to_pixmap=False) self.mode_button = QPushButton(icon=icon) self.update_mode_button() - self.mode_button.clicked.connect(self.set_dark_mode_enabled) + self.mode_button.clicked.connect(self.toggle_dark_mode) self.layout.addWidget(self.mode_button) self.setLayout(self.layout) self.setFixedSize(40, 40) @@ -41,7 +41,11 @@ class DarkModeButton(BECWidget, QWidget): self._dark_mode_enabled = state @Slot() - def set_dark_mode_enabled(self) -> None: + def toggle_dark_mode(self) -> None: + """ + Toggle the dark mode state. This will change the theme of the entire + application to dark or light mode. + """ self.dark_mode_enabled = not self.dark_mode_enabled self.update_mode_button() set_theme("dark" if self.dark_mode_enabled else "light") diff --git a/tests/unit_tests/test_dark_mode_button.py b/tests/unit_tests/test_dark_mode_button.py index c10060a8..203aa65e 100644 --- a/tests/unit_tests/test_dark_mode_button.py +++ b/tests/unit_tests/test_dark_mode_button.py @@ -34,11 +34,11 @@ def test_dark_mode_button_toggle(dark_mode_button): """ Test that the dark mode button toggles correctly. """ - dark_mode_button.set_dark_mode_enabled() + dark_mode_button.toggle_dark_mode() assert dark_mode_button.dark_mode_enabled is True assert dark_mode_button.mode_button.toolTip() == "Set Light Mode" - dark_mode_button.set_dark_mode_enabled() + dark_mode_button.toggle_dark_mode() assert dark_mode_button.dark_mode_enabled == False assert dark_mode_button.mode_button.toolTip() == "Set Dark Mode" @@ -63,8 +63,8 @@ def test_dark_mode_button_changes_theme(dark_mode_button): with mock.patch( "bec_widgets.widgets.dark_mode_button.dark_mode_button.set_theme" ) as mocked_set_theme: - dark_mode_button.set_dark_mode_enabled() + dark_mode_button.toggle_dark_mode() mocked_set_theme.assert_called_with("dark") - dark_mode_button.set_dark_mode_enabled() + dark_mode_button.toggle_dark_mode() mocked_set_theme.assert_called_with("light")