Skip to content

Commit bb57f01

Browse files
committed
Test
1 parent a6b4280 commit bb57f01

21 files changed

+885
-2
lines changed

.github/workflows/black_format.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
paths:
66
- '.github/workflows/black_format.yml'
77
- '**.py'
8+
push:
9+
paths:
10+
- '.github/workflows/black_format.yml'
11+
- '**.py'
812

913
jobs:
1014
black-format-check:

.github/workflows/pythonpackage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- 'Makefile'
1212
push:
1313
branches:
14-
- 'main'
14+
- '*'
1515

1616
jobs:
1717
build:

src/textual_dev/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ def colors() -> None:
219219
ColorsApp().run()
220220

221221

222+
@run.command("widgets")
223+
def widgets() -> None:
224+
"""Explore possible example_widgets."""
225+
from textual_dev.previews import WidgetsApp
226+
227+
WidgetsApp().run()
228+
229+
222230
@run.command("keys")
223231
def keys() -> None:
224232
"""Show key events."""

src/textual_dev/previews/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
from .colors import ColorsApp
55
from .easing import EasingApp
66
from .keys import KeysApp
7+
from .widgets import WidgetsApp
78

8-
__all__ = ["BorderApp", "ColorsApp", "EasingApp", "KeysApp"]
9+
__all__ = ["BorderApp", "ColorsApp", "EasingApp", "KeysApp", "WidgetsApp"]
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import random
2+
from statistics import mean
3+
4+
from textual.app import ComposeResult
5+
from textual.containers import Container, Center, Middle
6+
from textual.widgets import (
7+
DirectoryTree,
8+
Footer,
9+
Header,
10+
Input,
11+
Label,
12+
ListView,
13+
ListItem,
14+
LoadingIndicator,
15+
Sparkline,
16+
Static,
17+
Tree,
18+
ProgressBar,
19+
TabbedContent,
20+
TabPane,
21+
Markdown,
22+
Tabs,
23+
)
24+
25+
from .button import button_example
26+
from .checkbox import checkbox_example
27+
from .content_switcher import content_switcher_example
28+
from .data_table import data_table_example
29+
from .markdown import markdown_viewer_example, markdown_example
30+
from .option_list import option_list_example
31+
from .placeholder import placeholder_example
32+
from .pretty import pretty_example
33+
from .radio import radio_button_example, radio_set_example
34+
from .select import select_example, selection_list_example
35+
from .switch import switch_example
36+
37+
# from .text_log import text_log_example
38+
39+
40+
def directory_tree_example(id: str) -> ComposeResult:
41+
yield Container(DirectoryTree("./"), id=id)
42+
43+
44+
def footer_example(id: str) -> ComposeResult:
45+
yield Container(Footer(), id=id)
46+
47+
48+
def header_example(id: str) -> ComposeResult:
49+
yield Container(Header(), id=id)
50+
51+
52+
def input_example(id: str) -> ComposeResult:
53+
yield Container(
54+
Input(placeholder="First Name"), Input(placeholder="Last Name"), id=id
55+
)
56+
57+
58+
def label_example(id: str) -> ComposeResult:
59+
yield Container(Label("Hello, world!"), id=id)
60+
61+
62+
def list_item_example(id: str) -> ComposeResult:
63+
yield Container(
64+
ListView(
65+
ListItem(Label("One")),
66+
ListItem(Label("Two")),
67+
ListItem(Label("Three")),
68+
),
69+
id=id,
70+
)
71+
72+
yield Footer()
73+
74+
75+
def loading_example(id: str) -> ComposeResult:
76+
yield Container(LoadingIndicator(), id=id)
77+
78+
79+
def sparkline_example(id: str) -> ComposeResult:
80+
data = [random.expovariate(1 / 3) for _ in range(1000)]
81+
82+
yield Container(
83+
Sparkline(data, summary_function=max),
84+
Sparkline(data, summary_function=mean),
85+
Sparkline(data, summary_function=min),
86+
id=id,
87+
)
88+
89+
90+
def static_example(id: str) -> ComposeResult:
91+
yield Container(Static("Hello, world!"), id=id)
92+
93+
94+
def tree_example(id: str) -> ComposeResult:
95+
tree: Tree[dict] = Tree("Dune")
96+
tree.root.expand()
97+
characters = tree.root.add("Characters", expand=True)
98+
characters.add_leaf("Paul")
99+
characters.add_leaf("Jessica")
100+
characters.add_leaf("Chani")
101+
yield Container(tree, id=id)
102+
103+
104+
def progress_bar_example(id: str) -> ComposeResult:
105+
bar = ProgressBar(total=100, show_eta=False)
106+
bar.advance(50)
107+
yield Container(Center(Middle(bar)), id=id)
108+
109+
110+
def tabbed_content_example(id: str):
111+
content = TabbedContent()
112+
content._tab_content = [
113+
TabPane("Leto", Markdown("# Leto"), id="leto"),
114+
TabPane("Jessica", Markdown("# Jessica"), id="jessica"),
115+
TabPane("Paul", Markdown("# Paul"), id="paulo"),
116+
]
117+
# This does not work, reason why I used _tab_content above
118+
# content.add_pane(TabPane("Leto", Markdown("#Leto"), id="letoo"))
119+
# content.add_pane(TabPane("Jessica", Markdown(""), id="jessicoa"))
120+
# content.add_pane(TabPane("Paul", Markdown(""), id="paulo"))
121+
122+
yield Container(content, id=id)
123+
124+
125+
def tabs_example(id: str):
126+
yield Container(Tabs("First tab", "Second tab", "Third tab"), id=id)
127+
128+
129+
__all__ = [
130+
"button_example",
131+
"checkbox_example",
132+
"content_switcher_example",
133+
"data_table_example",
134+
"directory_tree_example",
135+
"footer_example",
136+
"header_example",
137+
"input_example",
138+
"label_example",
139+
"list_item_example",
140+
"loading_example",
141+
"markdown_viewer_example",
142+
"markdown_example",
143+
"option_list_example",
144+
"placeholder_example",
145+
"pretty_example",
146+
"progress_bar_example",
147+
"radio_button_example",
148+
"radio_set_example",
149+
"select_example",
150+
"selection_list_example",
151+
"sparkline_example",
152+
"static_example",
153+
"switch_example",
154+
"tabbed_content_example",
155+
"tabs_example",
156+
"tree_example",
157+
# "text_log_example",
158+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from textual.app import ComposeResult
2+
from textual.containers import Horizontal, VerticalScroll
3+
from textual.widgets import Static, Button
4+
5+
6+
def button_example(id: str) -> ComposeResult:
7+
yield Horizontal(
8+
VerticalScroll(
9+
Static("Standard Buttons", classes="header"),
10+
Button("Default"),
11+
Button("Primary!", variant="primary"),
12+
Button.success("Success!"),
13+
Button.warning("Warning!"),
14+
Button.error("Error!"),
15+
),
16+
VerticalScroll(
17+
Static("Disabled Buttons", classes="header"),
18+
Button("Default", disabled=True),
19+
Button("Primary!", variant="primary", disabled=True),
20+
Button.success("Success!", disabled=True),
21+
Button.warning("Warning!", disabled=True),
22+
Button.error("Error!", disabled=True),
23+
),
24+
id=id,
25+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from textual.app import ComposeResult
2+
from textual.containers import VerticalScroll, Container
3+
from textual.widgets import Checkbox
4+
5+
6+
def checkbox_example(id: str) -> ComposeResult:
7+
yield Container(
8+
VerticalScroll(
9+
Checkbox("Arrakis :sweat:"),
10+
Checkbox("Caladan"),
11+
Checkbox("Chusuk"),
12+
Checkbox("[b]Giedi Prime[/b]"),
13+
Checkbox("[magenta]Ginaz[/]"),
14+
Checkbox("Grumman", True),
15+
Checkbox("Kaitain", id="initial_focus"),
16+
Checkbox("Novebruns", True),
17+
),
18+
id=id,
19+
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from textual.app import ComposeResult
2+
from textual.containers import VerticalScroll, Container, Horizontal
3+
from textual.widgets import Button, ContentSwitcher, DataTable, Markdown
4+
5+
MARKDOWN_EXAMPLE = """# Three Flavours Cornetto
6+
7+
The Three Flavours Cornetto trilogy is an anthology series of British
8+
comedic genre films directed by Edgar Wright.
9+
10+
## Shaun of the Dead
11+
12+
| Flavour | UK Release Date | Director |
13+
| -- | -- | -- |
14+
| Strawberry | 2004-04-09 | Edgar Wright |
15+
16+
## Hot Fuzz
17+
18+
| Flavour | UK Release Date | Director |
19+
| -- | -- | -- |
20+
| Classico | 2007-02-17 | Edgar Wright |
21+
22+
## The World's End
23+
24+
| Flavour | UK Release Date | Director |
25+
| -- | -- | -- |
26+
| Mint | 2013-07-19 | Edgar Wright |
27+
"""
28+
29+
30+
def content_switcher_example(id: str) -> ComposeResult:
31+
table = DataTable(id="data-table")
32+
table.add_columns("Book", "Year")
33+
table.add_rows(
34+
[
35+
(title.ljust(35), year)
36+
for title, year in (
37+
("Dune", 1965),
38+
("Dune Messiah", 1969),
39+
("Children of Dune", 1976),
40+
("God Emperor of Dune", 1981),
41+
("Heretics of Dune", 1984),
42+
("Chapterhouse: Dune", 1985),
43+
)
44+
]
45+
)
46+
47+
yield Container(
48+
Horizontal(
49+
Button("DataTable", id="data-table"),
50+
Button("Markdown", id="markdown"),
51+
id="buttons",
52+
),
53+
ContentSwitcher(
54+
table,
55+
VerticalScroll(Markdown(MARKDOWN_EXAMPLE), id="markdown"),
56+
initial="data-table",
57+
id="content-switcher-example",
58+
),
59+
id=id,
60+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from textual.containers import Container
2+
from textual.app import ComposeResult
3+
from textual.widgets import DataTable
4+
5+
ROWS = [
6+
("lane", "swimmer", "country", "time"),
7+
(4, "Joseph Schooling", "Singapore", 50.39),
8+
(2, "Michael Phelps", "United States", 51.14),
9+
(5, "Chad le Clos", "South Africa", 51.14),
10+
(6, "László Cseh", "Hungary", 51.14),
11+
(3, "Li Zhuhao", "China", 51.26),
12+
(8, "Mehdy Metella", "France", 51.58),
13+
(7, "Tom Shields", "United States", 51.73),
14+
(1, "Aleksandr Sadovnikov", "Russia", 51.84),
15+
(10, "Darren Burns", "Scotland", 51.84),
16+
]
17+
18+
19+
def data_table_example(id: str) -> ComposeResult:
20+
table = DataTable()
21+
table.add_columns(*ROWS[0])
22+
table.add_rows(ROWS[1:])
23+
24+
yield Container(table, id=id)

0 commit comments

Comments
 (0)