mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
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:
42
docs/examples/guide/screens/modes01.py
Normal file
42
docs/examples/guide/screens/modes01.py
Normal 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()
|
||||
Reference in New Issue
Block a user