Fix variables in Screens, remove dark reactive from Screen

This commit is contained in:
Darren Burns
2022-10-19 14:16:13 +01:00
parent 586ffad1e5
commit d0cfd1a000
4 changed files with 27 additions and 6 deletions

View File

@@ -16,15 +16,36 @@ class CustomScreen(Screen):
yield Focusable(f"Screen {id(self)} - three")
yield Focusable(f"Screen {id(self)} - four")
yield Input(placeholder="Text input")
# yield Footer()
yield Footer()
class MyInstalledScreen(Screen):
def __init__(self, string: str):
super().__init__()
self.string = string
def compose(self) -> ComposeResult:
yield Static(f"Hello, world! {self.string}")
class ScreensFocusApp(App):
BINDINGS = [
Binding("plus", "push_new_screen", "Push"),
Binding("minus", "pop_top_screen", "Pop"),
Binding("d", "toggle_dark", "Toggle Dark"),
Binding("q", "push_screen('q')", "Screen Q"),
Binding("w", "push_screen('w')", "Screen W"),
Binding("e", "push_screen('e')", "Screen E"),
Binding("r", "push_screen('r')", "Screen R"),
]
SCREENS = {
"q": MyInstalledScreen("q"),
"w": MyInstalledScreen("w"),
"e": MyInstalledScreen("e"),
"r": MyInstalledScreen("r"),
}
def compose(self) -> ComposeResult:
yield Focusable("App - one")
yield Input(placeholder="Text input")
@@ -32,7 +53,7 @@ class ScreensFocusApp(App):
yield Focusable("App - two")
yield Focusable("App - three")
yield Focusable("App - four")
# yield Footer()
yield Footer()
def action_push_new_screen(self):
self.push_screen(CustomScreen())
@@ -43,6 +64,9 @@ class ScreensFocusApp(App):
except ScreenStackError:
pass
def _action_toggle_dark(self):
self.dark = not self.dark
app = ScreensFocusApp(css_path="screens_focus.css")
if __name__ == "__main__":

View File

@@ -353,8 +353,6 @@ class App(Generic[ReturnType], DOMNode):
def watch_dark(self, dark: bool) -> None:
"""Watches the dark bool."""
self.screen.dark = dark
self.set_class(dark, "-dark-mode")
self.set_class(not dark, "-light-mode")
self.refresh_css()

View File

@@ -192,7 +192,7 @@ class Stylesheet:
variables (dict[str, str]): A mapping of name to variable.
"""
self._variables = variables
self._variables_tokens = None
self.__variable_tokens = None
def _parse_rules(
self,

View File

@@ -38,7 +38,6 @@ class Screen(Widget):
}
"""
dark: Reactive[bool] = Reactive(False)
focused: Reactive[Widget | None] = Reactive(None)
def __init__(