mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'main' into add-containers
This commit is contained in:
27
docs/examples/widgets/content_switcher.css
Normal file
27
docs/examples/widgets/content_switcher.css
Normal file
@@ -0,0 +1,27 @@
|
||||
Screen {
|
||||
align: center middle;
|
||||
}
|
||||
|
||||
#buttons {
|
||||
margin-top: 1;
|
||||
height: 3;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
ContentSwitcher {
|
||||
background: $panel;
|
||||
border: round $primary;
|
||||
width: 90%;
|
||||
height: 80%;
|
||||
}
|
||||
|
||||
DataTable {
|
||||
background: $panel;
|
||||
}
|
||||
|
||||
MarkdownH2 {
|
||||
background: $primary;
|
||||
color: yellow;
|
||||
border: none;
|
||||
padding: 0;
|
||||
}
|
||||
64
docs/examples/widgets/content_switcher.py
Normal file
64
docs/examples/widgets/content_switcher.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Horizontal
|
||||
from textual.widgets import Button, ContentSwitcher, DataTable, Markdown
|
||||
|
||||
MARKDOWN_EXAMPLE = """# Three Flavours Cornetto
|
||||
|
||||
The Three Flavours Cornetto trilogy is an anthology series of British
|
||||
comedic genre films directed by Edgar Wright.
|
||||
|
||||
## Shaun of the Dead
|
||||
|
||||
| Flavour | UK Release Date | Director |
|
||||
| -- | -- | -- |
|
||||
| Strawberry | 2004-04-09 | Edgar Wright |
|
||||
|
||||
## Hot Fuzz
|
||||
|
||||
| Flavour | UK Release Date | Director |
|
||||
| -- | -- | -- |
|
||||
| Classico | 2007-02-17 | Edgar Wright |
|
||||
|
||||
## The World's End
|
||||
|
||||
| Flavour | UK Release Date | Director |
|
||||
| -- | -- | -- |
|
||||
| Mint | 2013-07-19 | Edgar Wright |
|
||||
"""
|
||||
|
||||
|
||||
class ContentSwitcherApp(App[None]):
|
||||
CSS_PATH = "content_switcher.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with Horizontal(id="buttons"): # (1)!
|
||||
yield Button("DataTable", id="data-table") # (2)!
|
||||
yield Button("Markdown", id="markdown") # (3)!
|
||||
|
||||
with ContentSwitcher(initial="data-table"): # (4)!
|
||||
yield DataTable(id="data-table")
|
||||
yield Markdown(MARKDOWN_EXAMPLE, id="markdown")
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.query_one(ContentSwitcher).current = event.button.id # (5)!
|
||||
|
||||
def on_mount(self) -> None:
|
||||
table = self.query_one(DataTable)
|
||||
table.add_columns("Book", "Year")
|
||||
table.add_rows(
|
||||
[
|
||||
(title.ljust(35), year)
|
||||
for title, year in (
|
||||
("Dune", 1965),
|
||||
("Dune Messiah", 1969),
|
||||
("Children of Dune", 1976),
|
||||
("God Emperor of Dune", 1981),
|
||||
("Heretics of Dune", 1984),
|
||||
("Chapterhouse: Dune", 1985),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ContentSwitcherApp().run()
|
||||
Reference in New Issue
Block a user