mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
refactor(darkmodebutton): renamed set_dark_mode_enabled to toggle_dark_mode
This commit is contained in:
@ -2292,9 +2292,10 @@ class BECWaveformWidget(RPCBase):
|
|||||||
|
|
||||||
class DarkModeButton(RPCBase):
|
class DarkModeButton(RPCBase):
|
||||||
@rpc_call
|
@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.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ from bec_widgets.utils.colors import set_theme
|
|||||||
|
|
||||||
|
|
||||||
class DarkModeButton(BECWidget, QWidget):
|
class DarkModeButton(BECWidget, QWidget):
|
||||||
USER_ACCESS = ["set_dark_mode_enabled"]
|
USER_ACCESS = ["toggle_dark_mode"]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, parent: QWidget | None = None, client=None, gui_id: str | None = None
|
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)
|
icon = material_icon("dark_mode", size=(20, 20), convert_to_pixmap=False)
|
||||||
self.mode_button = QPushButton(icon=icon)
|
self.mode_button = QPushButton(icon=icon)
|
||||||
self.update_mode_button()
|
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.layout.addWidget(self.mode_button)
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
self.setFixedSize(40, 40)
|
self.setFixedSize(40, 40)
|
||||||
@ -41,7 +41,11 @@ class DarkModeButton(BECWidget, QWidget):
|
|||||||
self._dark_mode_enabled = state
|
self._dark_mode_enabled = state
|
||||||
|
|
||||||
@Slot()
|
@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.dark_mode_enabled = not self.dark_mode_enabled
|
||||||
self.update_mode_button()
|
self.update_mode_button()
|
||||||
set_theme("dark" if self.dark_mode_enabled else "light")
|
set_theme("dark" if self.dark_mode_enabled else "light")
|
||||||
|
@ -34,11 +34,11 @@ def test_dark_mode_button_toggle(dark_mode_button):
|
|||||||
"""
|
"""
|
||||||
Test that the dark mode button toggles correctly.
|
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.dark_mode_enabled is True
|
||||||
assert dark_mode_button.mode_button.toolTip() == "Set Light Mode"
|
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.dark_mode_enabled == False
|
||||||
assert dark_mode_button.mode_button.toolTip() == "Set Dark Mode"
|
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(
|
with mock.patch(
|
||||||
"bec_widgets.widgets.dark_mode_button.dark_mode_button.set_theme"
|
"bec_widgets.widgets.dark_mode_button.dark_mode_button.set_theme"
|
||||||
) as mocked_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")
|
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")
|
mocked_set_theme.assert_called_with("light")
|
||||||
|
Reference in New Issue
Block a user