tabs demo

This commit is contained in:
Will McGugan
2024-11-15 16:02:33 +00:00
parent f74e4db5e0
commit 326e6c4fe3
2 changed files with 69 additions and 1 deletions

View File

@@ -413,3 +413,46 @@ MOVIES_JSON = """{
}"""
MOVIES_TREE = json.loads(MOVIES_JSON)
DUNE_BIOS = [
{
"name": "Paul Atreides",
"description": "Heir to House Atreides who becomes the Fremen messiah Muad'Dib. Born with extraordinary mental abilities due to Bene Gesserit breeding program.",
},
{
"name": "Lady Jessica",
"description": "Bene Gesserit concubine to Duke Leto and mother of Paul. Defied her order by bearing a son instead of a daughter, disrupting centuries of careful breeding.",
},
{
"name": "Baron Vladimir Harkonnen",
"description": "Cruel and corpulent leader of House Harkonnen, sworn enemy of House Atreides. Known for his cunning and brutality in pursuing power.",
},
{
"name": "Leto Atreides",
"description": "Noble Duke and father of Paul, known for his honor and just rule. Accepts governorship of Arrakis despite knowing it's likely a trap.",
},
{
"name": "Stilgar",
"description": "Leader of the Fremen Sietch Tabr, becomes a loyal supporter of Paul. Skilled warrior who helps train Paul in Fremen ways.",
},
{
"name": "Chani",
"description": "Fremen warrior and daughter of planetologist Liet-Kynes. Becomes Paul's concubine and true love after appearing in his prescient visions.",
},
{
"name": "Thufir Hawat",
"description": "Mentat and Master of Assassins for House Atreides. Serves three generations of Atreides with his superhuman computational skills.",
},
{
"name": "Duncan Idaho",
"description": "Swordmaster of the Ginaz, loyal to House Atreides. Known for his exceptional fighting skills and sacrifice to save Paul and Jessica.",
},
{
"name": "Gurney Halleck",
"description": "Warrior-troubadour of House Atreides, skilled with sword and baliset. Serves as Paul's weapons teacher and loyal friend.",
},
{
"name": "Dr. Yueh",
"description": "Suk doctor conditioned against taking human life, but betrays House Atreides after the Harkonnens torture his wife. Imperial Conditioning broken.",
},
]

View File

@@ -11,7 +11,7 @@ from rich.traceback import Traceback
from textual import containers, events, lazy, on
from textual.app import ComposeResult
from textual.binding import Binding
from textual.demo.data import COUNTRIES, MOVIES, MOVIES_TREE
from textual.demo.data import COUNTRIES, DUNE_BIOS, MOVIES, MOVIES_TREE
from textual.demo.page import PageScreen
from textual.reactive import reactive, var
from textual.suggester import SuggestFromList
@@ -35,6 +35,7 @@ from textual.widgets import (
RichLog,
Select,
Sparkline,
Static,
Switch,
TabbedContent,
TextArea,
@@ -636,6 +637,29 @@ Switches {
self.set_timer(0.3, switch_theme)
class TabsDemo(containers.VerticalGroup):
DEFAULT_CLASSES = "column"
TABS_MD = """\
## Tabs
A navigable list of section headers.
Typically used with `ContentTabs`, to display additional content associate with each tab.
Use the cursor keys to navigate.
"""
DEFAULT_CSS = """
.bio { padding: 1 2; background: $boost; color: $foreground-muted; }
"""
def compose(self) -> ComposeResult:
yield Markdown(self.TABS_MD)
with TabbedContent(*[bio["name"] for bio in DUNE_BIOS]):
for bio in DUNE_BIOS:
yield Static(bio["description"], classes="bio")
class Trees(containers.VerticalGroup):
DEFAULT_CLASSES = "column"
TREES_MD = """\
@@ -778,6 +802,7 @@ class WidgetsScreen(PageScreen):
yield Selects()
yield Sparklines()
yield Switches()
yield TabsDemo()
yield TextAreas()
yield Trees()
yield YourWidgets()