Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dark mode after textual update #445

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
JoeZiminski marked this conversation as resolved.
Show resolved Hide resolved

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
Loading