Skip to content

Commit

Permalink
Fix dark mode after textual update.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeZiminski committed Dec 4, 2024
1 parent 3223577 commit a487ff5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion datashuttle/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ def compose(self) -> ComposeResult:
)

def on_mount(self) -> None:
self.dark = self.load_global_settings()["dark_mode"]
self.set_dark_mode(self.load_global_settings()["dark_mode"])

def set_dark_mode(self, dark_mode: bool) -> None:
if dark_mode:
self.theme = "textual-dark"
else:
self.theme = "textual-light"

def on_button_pressed(self, event: Button.Pressed) -> None:
"""
Expand Down
3 changes: 2 additions & 1 deletion datashuttle/tui/screens/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def on_mount(self) -> None:
def on_radio_set_changed(self, event: RadioSet.Changed) -> None:
label = str(event.pressed.label)
assert label in ["Light Mode", "Dark Mode"]

dark_mode = label == "Dark Mode"
self.mainwindow.set_dark_mode(dark_mode)

self.mainwindow.dark = dark_mode
self.global_settings["dark_mode"] = dark_mode
self.mainwindow.save_global_settings(self.global_settings)

Expand Down
8 changes: 4 additions & 4 deletions tests/tests_tui/test_tui_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestTuiSettings(TuiBase):
"""

@pytest.mark.asyncio
async def test_light_dark_mode(self, empty_project_paths):
async def test_light_dark_mode(self):
"""
Check the light / dark mode switch which is stored
in the global tui settings. Global refers to set
Expand All @@ -24,21 +24,21 @@ async def test_light_dark_mode(self, empty_project_paths):
)

# Check default is dark mode, switch to light mode
assert pilot.app.dark is True
assert pilot.app.theme == "textual-dark"
assert pilot.app.load_global_settings()["dark_mode"] is True

await self.scroll_to_click_pause(
pilot, "#settings_screen_light_mode_radiobutton"
)
assert pilot.app.dark is False
assert pilot.app.theme == "textual-light"
assert pilot.app.load_global_settings()["dark_mode"] is False

# Switch back to dark mode
await self.scroll_to_click_pause(
pilot, "#settings_screen_dark_mode_radiobutton"
)

assert pilot.app.dark is True
assert pilot.app.theme == "textual-dark"
assert pilot.app.load_global_settings()["dark_mode"] is True

await pilot.pause()
Expand Down

0 comments on commit a487ff5

Please sign in to comment.