Skip to content

Commit

Permalink
Remove App.dark from App and docs examples
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Oct 24, 2024
1 parent eab07e6 commit f8af200
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 71 deletions.
4 changes: 3 additions & 1 deletion docs/examples/events/on_decorator01.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def on_button_pressed(self, event: Button.Pressed) -> None: # (1)!
if event.button.id == "bell":
self.bell()
elif event.button.has_class("toggle", "dark"):
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)
elif event.button.id == "quit":
self.exit()

Expand Down
4 changes: 3 additions & 1 deletion docs/examples/events/on_decorator02.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def play_bell(self):
@on(Button.Pressed, ".toggle.dark") # (2)!
def toggle_dark(self):
"""Called when the 'toggle dark' button is pressed."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)

@on(Button.Pressed, "#quit") # (3)!
def quit(self):
Expand Down
1 change: 0 additions & 1 deletion docs/examples/getting_started/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class ConsoleApp(App):
def compose(self):
self.dark = True
yield Static(DevConsoleHeader())


Expand Down
4 changes: 3 additions & 1 deletion docs/examples/tutorial/stopwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def action_remove_stopwatch(self) -> None:

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)


if __name__ == "__main__":
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/tutorial/stopwatch01.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from textual.app import App, ComposeResult
from textual.widgets import Header, Footer
from textual.widgets import Footer, Header


class StopwatchApp(App):
Expand All @@ -14,7 +14,9 @@ def compose(self) -> ComposeResult:

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/tutorial/stopwatch02.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def compose(self) -> ComposeResult:

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/tutorial/stopwatch03.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def compose(self) -> ComposeResult:

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/tutorial/stopwatch04.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def compose(self) -> ComposeResult:

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/tutorial/stopwatch05.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def compose(self) -> ComposeResult:

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/tutorial/stopwatch06.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def compose(self) -> ComposeResult:

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)


if __name__ == "__main__":
Expand Down
14 changes: 0 additions & 14 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,6 @@ class MyApp(App[None]):
sub_title: Reactive[str] = Reactive("", compute=False)
"""The app's sub-title, combined with [`title`][textual.app.App.title] in the header."""

dark: Reactive[bool] = Reactive(True, compute=False)
"""Use a dark theme if `True`, otherwise use a light theme.
Modify this attribute to switch between light and dark themes.
Example:
```python
self.app.dark = not self.app.dark # Toggle dark mode
```
"""
app_focus = Reactive(True, compute=False)
"""Indicates if the app has focus.
Expand Down Expand Up @@ -1578,10 +1568,6 @@ async def run_callback() -> CallThreadReturnType:
result = future.result()
return result

def action_toggle_dark(self) -> None:
"""An [action](/guide/actions) to toggle dark mode."""
self.dark = not self.dark

def action_change_theme(self) -> None:
"""An [action](/guide/actions) to change the current theme."""
self.app.push_screen(
Expand Down
6 changes: 3 additions & 3 deletions src/textual/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ class Title(Static):

class DarkSwitch(Horizontal):
def compose(self) -> ComposeResult:
yield Switch(value=self.app.dark)
yield Switch(value=self.app.theme == "textual-dark")
yield Static("Dark mode toggle", classes="label")

def on_mount(self) -> None:
self.watch(self.app, "dark", self.on_dark_change, init=False)

def on_dark_change(self) -> None:
self.query_one(Switch).value = self.app.dark
self.query_one(Switch).value = self.app.theme == "textual-dark"

def on_switch_changed(self, event: Switch.Changed) -> None:
self.app.dark = event.value
self.app.theme = "textual-dark" if event.value else "textual-light"


class Welcome(Container):
Expand Down
43 changes: 0 additions & 43 deletions tests/test_dark_toggle.py

This file was deleted.

0 comments on commit f8af200

Please sign in to comment.