Modes docs (#3233)

* Modes docs

* Added current mode

* fix docstring

* diagrams

* Update docs/guide/screens.md

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* Update docs/guide/screens.md

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>

* words

---------

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
This commit is contained in:
Will McGugan
2023-09-04 17:40:40 +01:00
committed by GitHub
parent 6d4fcaa4c6
commit cbed79c7eb
6 changed files with 147 additions and 7 deletions

View File

@@ -0,0 +1,42 @@
from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Footer, Placeholder
class DashboardScreen(Screen):
def compose(self) -> ComposeResult:
yield Placeholder("Dashboard Screen")
yield Footer()
class SettingsScreen(Screen):
def compose(self) -> ComposeResult:
yield Placeholder("Settings Screen")
yield Footer()
class HelpScreen(Screen):
def compose(self) -> ComposeResult:
yield Placeholder("Help Screen")
yield Footer()
class ModesApp(App):
BINDINGS = [
("d", "switch_mode('dashboard')", "Dashboard"), # (1)!
("s", "switch_mode('settings')", "Settings"),
("h", "switch_mode('help')", "Help"),
]
MODES = {
"dashboard": DashboardScreen, # (2)!
"settings": SettingsScreen,
"help": HelpScreen,
}
def on_mount(self) -> None:
self.switch_mode("dashboard") # (3)!
if __name__ == "__main__":
app = ModesApp()
app.run()