1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
from textual.app import App, ComposeResult
from textual.widgets import Collapsible, Footer, Label, Markdown
LETO = """\
# Duke Leto I Atreides
Head of House Atreides."""
JESSICA = """
# Lady Jessica
Bene Gesserit and concubine of Leto, and mother of Paul and Alia.
"""
PAUL = """
# Paul Atreides
Son of Leto and Jessica.
"""
class CollapsibleApp(App[None]):
"""An example of collapsible container."""
BINDINGS = [
("c", "collapse_or_expand(True)", "Collapse All"),
("e", "collapse_or_expand(False)", "Expand All"),
]
def compose(self) -> ComposeResult:
"""Compose app with collapsible containers."""
yield Footer()
with Collapsible(collapsed=False, title="Leto"):
yield Label(LETO)
yield Collapsible(Markdown(JESSICA), collapsed=False, title="Jessica")
with Collapsible(collapsed=True, title="Paul"):
yield Markdown(PAUL)
def action_collapse_or_expand(self, collapse: bool) -> None:
for child in self.walk_children(Collapsible):
child.collapsed = collapse
if __name__ == "__main__":
app = CollapsibleApp()
app.run()
|