Skip to content

Commit 326e6c4

Browse files
committed
tabs demo
1 parent f74e4db commit 326e6c4

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

src/textual/demo/data.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,46 @@
413413
}"""
414414

415415
MOVIES_TREE = json.loads(MOVIES_JSON)
416+
417+
DUNE_BIOS = [
418+
{
419+
"name": "Paul Atreides",
420+
"description": "Heir to House Atreides who becomes the Fremen messiah Muad'Dib. Born with extraordinary mental abilities due to Bene Gesserit breeding program.",
421+
},
422+
{
423+
"name": "Lady Jessica",
424+
"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.",
425+
},
426+
{
427+
"name": "Baron Vladimir Harkonnen",
428+
"description": "Cruel and corpulent leader of House Harkonnen, sworn enemy of House Atreides. Known for his cunning and brutality in pursuing power.",
429+
},
430+
{
431+
"name": "Leto Atreides",
432+
"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.",
433+
},
434+
{
435+
"name": "Stilgar",
436+
"description": "Leader of the Fremen Sietch Tabr, becomes a loyal supporter of Paul. Skilled warrior who helps train Paul in Fremen ways.",
437+
},
438+
{
439+
"name": "Chani",
440+
"description": "Fremen warrior and daughter of planetologist Liet-Kynes. Becomes Paul's concubine and true love after appearing in his prescient visions.",
441+
},
442+
{
443+
"name": "Thufir Hawat",
444+
"description": "Mentat and Master of Assassins for House Atreides. Serves three generations of Atreides with his superhuman computational skills.",
445+
},
446+
{
447+
"name": "Duncan Idaho",
448+
"description": "Swordmaster of the Ginaz, loyal to House Atreides. Known for his exceptional fighting skills and sacrifice to save Paul and Jessica.",
449+
},
450+
{
451+
"name": "Gurney Halleck",
452+
"description": "Warrior-troubadour of House Atreides, skilled with sword and baliset. Serves as Paul's weapons teacher and loyal friend.",
453+
},
454+
{
455+
"name": "Dr. Yueh",
456+
"description": "Suk doctor conditioned against taking human life, but betrays House Atreides after the Harkonnens torture his wife. Imperial Conditioning broken.",
457+
},
458+
]

src/textual/demo/widgets.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from textual import containers, events, lazy, on
1212
from textual.app import ComposeResult
1313
from textual.binding import Binding
14-
from textual.demo.data import COUNTRIES, MOVIES, MOVIES_TREE
14+
from textual.demo.data import COUNTRIES, DUNE_BIOS, MOVIES, MOVIES_TREE
1515
from textual.demo.page import PageScreen
1616
from textual.reactive import reactive, var
1717
from textual.suggester import SuggestFromList
@@ -35,6 +35,7 @@
3535
RichLog,
3636
Select,
3737
Sparkline,
38+
Static,
3839
Switch,
3940
TabbedContent,
4041
TextArea,
@@ -636,6 +637,29 @@ def switch_theme() -> None:
636637
self.set_timer(0.3, switch_theme)
637638

638639

640+
class TabsDemo(containers.VerticalGroup):
641+
DEFAULT_CLASSES = "column"
642+
TABS_MD = """\
643+
## Tabs
644+
645+
A navigable list of section headers.
646+
647+
Typically used with `ContentTabs`, to display additional content associate with each tab.
648+
649+
Use the cursor keys to navigate.
650+
651+
"""
652+
DEFAULT_CSS = """
653+
.bio { padding: 1 2; background: $boost; color: $foreground-muted; }
654+
"""
655+
656+
def compose(self) -> ComposeResult:
657+
yield Markdown(self.TABS_MD)
658+
with TabbedContent(*[bio["name"] for bio in DUNE_BIOS]):
659+
for bio in DUNE_BIOS:
660+
yield Static(bio["description"], classes="bio")
661+
662+
639663
class Trees(containers.VerticalGroup):
640664
DEFAULT_CLASSES = "column"
641665
TREES_MD = """\
@@ -778,6 +802,7 @@ def compose(self) -> ComposeResult:
778802
yield Selects()
779803
yield Sparklines()
780804
yield Switches()
805+
yield TabsDemo()
781806
yield TextAreas()
782807
yield Trees()
783808
yield YourWidgets()

0 commit comments

Comments
 (0)