0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

refactor(darkmodebutton): renamed set_dark_mode_enabled to toggle_dark_mode

This commit is contained in:
2024-08-25 11:36:06 +02:00
parent 406c263746
commit c70724a456
3 changed files with 14 additions and 9 deletions

View File

@ -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.
"""

View File

@ -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")

View File

@ -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")