Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelkraleu committed Aug 11, 2023
1 parent a6b4280 commit bb57f01
Show file tree
Hide file tree
Showing 21 changed files with 885 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/black_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
paths:
- '.github/workflows/black_format.yml'
- '**.py'
push:
paths:
- '.github/workflows/black_format.yml'
- '**.py'

jobs:
black-format-check:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- 'Makefile'
push:
branches:
- 'main'
- '*'

jobs:
build:
Expand Down
8 changes: 8 additions & 0 deletions src/textual_dev/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ def colors() -> None:
ColorsApp().run()


@run.command("widgets")
def widgets() -> None:
"""Explore possible example_widgets."""
from textual_dev.previews import WidgetsApp

WidgetsApp().run()


@run.command("keys")
def keys() -> None:
"""Show key events."""
Expand Down
3 changes: 2 additions & 1 deletion src/textual_dev/previews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
from .colors import ColorsApp
from .easing import EasingApp
from .keys import KeysApp
from .widgets import WidgetsApp

__all__ = ["BorderApp", "ColorsApp", "EasingApp", "KeysApp"]
__all__ = ["BorderApp", "ColorsApp", "EasingApp", "KeysApp", "WidgetsApp"]
158 changes: 158 additions & 0 deletions src/textual_dev/previews/example_widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import random
from statistics import mean

from textual.app import ComposeResult
from textual.containers import Container, Center, Middle
from textual.widgets import (
DirectoryTree,
Footer,
Header,
Input,
Label,
ListView,
ListItem,
LoadingIndicator,
Sparkline,
Static,
Tree,
ProgressBar,
TabbedContent,
TabPane,
Markdown,
Tabs,
)

from .button import button_example
from .checkbox import checkbox_example
from .content_switcher import content_switcher_example
from .data_table import data_table_example
from .markdown import markdown_viewer_example, markdown_example
from .option_list import option_list_example
from .placeholder import placeholder_example
from .pretty import pretty_example
from .radio import radio_button_example, radio_set_example
from .select import select_example, selection_list_example
from .switch import switch_example

# from .text_log import text_log_example


def directory_tree_example(id: str) -> ComposeResult:
yield Container(DirectoryTree("./"), id=id)


def footer_example(id: str) -> ComposeResult:
yield Container(Footer(), id=id)


def header_example(id: str) -> ComposeResult:
yield Container(Header(), id=id)


def input_example(id: str) -> ComposeResult:
yield Container(
Input(placeholder="First Name"), Input(placeholder="Last Name"), id=id
)


def label_example(id: str) -> ComposeResult:
yield Container(Label("Hello, world!"), id=id)


def list_item_example(id: str) -> ComposeResult:
yield Container(
ListView(
ListItem(Label("One")),
ListItem(Label("Two")),
ListItem(Label("Three")),
),
id=id,
)

yield Footer()


def loading_example(id: str) -> ComposeResult:
yield Container(LoadingIndicator(), id=id)


def sparkline_example(id: str) -> ComposeResult:
data = [random.expovariate(1 / 3) for _ in range(1000)]

yield Container(
Sparkline(data, summary_function=max),
Sparkline(data, summary_function=mean),
Sparkline(data, summary_function=min),
id=id,
)


def static_example(id: str) -> ComposeResult:
yield Container(Static("Hello, world!"), id=id)


def tree_example(id: str) -> ComposeResult:
tree: Tree[dict] = Tree("Dune")
tree.root.expand()
characters = tree.root.add("Characters", expand=True)
characters.add_leaf("Paul")
characters.add_leaf("Jessica")
characters.add_leaf("Chani")
yield Container(tree, id=id)


def progress_bar_example(id: str) -> ComposeResult:
bar = ProgressBar(total=100, show_eta=False)
bar.advance(50)
yield Container(Center(Middle(bar)), id=id)


def tabbed_content_example(id: str):
content = TabbedContent()
content._tab_content = [
TabPane("Leto", Markdown("# Leto"), id="leto"),
TabPane("Jessica", Markdown("# Jessica"), id="jessica"),
TabPane("Paul", Markdown("# Paul"), id="paulo"),
]
# This does not work, reason why I used _tab_content above
# content.add_pane(TabPane("Leto", Markdown("#Leto"), id="letoo"))
# content.add_pane(TabPane("Jessica", Markdown(""), id="jessicoa"))
# content.add_pane(TabPane("Paul", Markdown(""), id="paulo"))

yield Container(content, id=id)


def tabs_example(id: str):
yield Container(Tabs("First tab", "Second tab", "Third tab"), id=id)


__all__ = [
"button_example",
"checkbox_example",
"content_switcher_example",
"data_table_example",
"directory_tree_example",
"footer_example",
"header_example",
"input_example",
"label_example",
"list_item_example",
"loading_example",
"markdown_viewer_example",
"markdown_example",
"option_list_example",
"placeholder_example",
"pretty_example",
"progress_bar_example",
"radio_button_example",
"radio_set_example",
"select_example",
"selection_list_example",
"sparkline_example",
"static_example",
"switch_example",
"tabbed_content_example",
"tabs_example",
"tree_example",
# "text_log_example",
]
25 changes: 25 additions & 0 deletions src/textual_dev/previews/example_widgets/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from textual.app import ComposeResult
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Static, Button


def button_example(id: str) -> ComposeResult:
yield Horizontal(
VerticalScroll(
Static("Standard Buttons", classes="header"),
Button("Default"),
Button("Primary!", variant="primary"),
Button.success("Success!"),
Button.warning("Warning!"),
Button.error("Error!"),
),
VerticalScroll(
Static("Disabled Buttons", classes="header"),
Button("Default", disabled=True),
Button("Primary!", variant="primary", disabled=True),
Button.success("Success!", disabled=True),
Button.warning("Warning!", disabled=True),
Button.error("Error!", disabled=True),
),
id=id,
)
19 changes: 19 additions & 0 deletions src/textual_dev/previews/example_widgets/checkbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from textual.app import ComposeResult
from textual.containers import VerticalScroll, Container
from textual.widgets import Checkbox


def checkbox_example(id: str) -> ComposeResult:
yield Container(
VerticalScroll(
Checkbox("Arrakis :sweat:"),
Checkbox("Caladan"),
Checkbox("Chusuk"),
Checkbox("[b]Giedi Prime[/b]"),
Checkbox("[magenta]Ginaz[/]"),
Checkbox("Grumman", True),
Checkbox("Kaitain", id="initial_focus"),
Checkbox("Novebruns", True),
),
id=id,
)
60 changes: 60 additions & 0 deletions src/textual_dev/previews/example_widgets/content_switcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from textual.app import ComposeResult
from textual.containers import VerticalScroll, Container, 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 |
"""


def content_switcher_example(id: str) -> ComposeResult:
table = DataTable(id="data-table")
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),
)
]
)

yield Container(
Horizontal(
Button("DataTable", id="data-table"),
Button("Markdown", id="markdown"),
id="buttons",
),
ContentSwitcher(
table,
VerticalScroll(Markdown(MARKDOWN_EXAMPLE), id="markdown"),
initial="data-table",
id="content-switcher-example",
),
id=id,
)
24 changes: 24 additions & 0 deletions src/textual_dev/previews/example_widgets/data_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from textual.containers import Container
from textual.app import ComposeResult
from textual.widgets import DataTable

ROWS = [
("lane", "swimmer", "country", "time"),
(4, "Joseph Schooling", "Singapore", 50.39),
(2, "Michael Phelps", "United States", 51.14),
(5, "Chad le Clos", "South Africa", 51.14),
(6, "László Cseh", "Hungary", 51.14),
(3, "Li Zhuhao", "China", 51.26),
(8, "Mehdy Metella", "France", 51.58),
(7, "Tom Shields", "United States", 51.73),
(1, "Aleksandr Sadovnikov", "Russia", 51.84),
(10, "Darren Burns", "Scotland", 51.84),
]


def data_table_example(id: str) -> ComposeResult:
table = DataTable()
table.add_columns(*ROWS[0])
table.add_rows(ROWS[1:])

yield Container(table, id=id)
Loading

0 comments on commit bb57f01

Please sign in to comment.