mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Remove App.dark from App and docs examples
This commit is contained in:
@@ -16,7 +16,9 @@ class OnDecoratorApp(App):
|
||||
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()
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ class OnDecoratorApp(App):
|
||||
@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):
|
||||
|
||||
@@ -10,7 +10,6 @@ from textual.widgets import Static
|
||||
|
||||
class ConsoleApp(App):
|
||||
def compose(self):
|
||||
self.dark = True
|
||||
yield Static(DevConsoleHeader())
|
||||
|
||||
|
||||
|
||||
@@ -99,7 +99,9 @@ class StopwatchApp(App):
|
||||
|
||||
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__":
|
||||
|
||||
@@ -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):
|
||||
@@ -14,7 +14,9 @@ class StopwatchApp(App):
|
||||
|
||||
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__":
|
||||
|
||||
@@ -31,7 +31,9 @@ class StopwatchApp(App):
|
||||
|
||||
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__":
|
||||
|
||||
@@ -32,7 +32,9 @@ class StopwatchApp(App):
|
||||
|
||||
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__":
|
||||
|
||||
@@ -39,7 +39,9 @@ class StopwatchApp(App):
|
||||
|
||||
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__":
|
||||
|
||||
@@ -59,7 +59,9 @@ class StopwatchApp(App):
|
||||
|
||||
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__":
|
||||
|
||||
@@ -82,7 +82,9 @@ class StopwatchApp(App):
|
||||
|
||||
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__":
|
||||
|
||||
@@ -508,16 +508,6 @@ class App(Generic[ReturnType], DOMNode):
|
||||
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.
|
||||
|
||||
@@ -1578,10 +1568,6 @@ class App(Generic[ReturnType], DOMNode):
|
||||
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(
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class OnLoadDarkSwitch(App[None]):
|
||||
"""App for testing toggling dark mode in on_load."""
|
||||
|
||||
def on_load(self) -> None:
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
async def test_toggle_dark_on_load() -> None:
|
||||
"""It should be possible to toggle dark mode in on_load."""
|
||||
async with OnLoadDarkSwitch().run_test() as pilot:
|
||||
assert not pilot.app.dark
|
||||
|
||||
|
||||
class OnMountDarkSwitch(App[None]):
|
||||
"""App for testing toggling dark mode in on_mount."""
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
async def test_toggle_dark_on_mount() -> None:
|
||||
"""It should be possible to toggle dark mode in on_mount."""
|
||||
async with OnMountDarkSwitch().run_test() as pilot:
|
||||
assert not pilot.app.dark
|
||||
|
||||
|
||||
class ActionDarkSwitch(App[None]):
|
||||
"""App for testing toggling dark mode from an action."""
|
||||
|
||||
BINDINGS = [("d", "toggle", "Toggle Dark Mode")]
|
||||
|
||||
def action_toggle(self) -> None:
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
async def test_toggle_dark_in_action() -> None:
|
||||
"""It should be possible to toggle dark mode with an action."""
|
||||
async with OnMountDarkSwitch().run_test() as pilot:
|
||||
await pilot.press("d")
|
||||
assert not pilot.app.dark
|
||||
Reference in New Issue
Block a user