|
| 1 | +import random |
| 2 | +from statistics import mean |
| 3 | + |
| 4 | +from textual.app import ComposeResult |
| 5 | +from textual.containers import Container |
| 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 | +) |
| 19 | + |
| 20 | +from .button import button_example |
| 21 | +from .checkbox import checkbox_example |
| 22 | +from .data_table import data_table_example |
| 23 | +from .markdown import markdown_viewer_example, markdown_example |
| 24 | +from .option_list import option_list_example |
| 25 | +from .placeholder import placeholder_example |
| 26 | +from .pretty import pretty_example |
| 27 | +from .radio import radio_button_example, radio_set_example |
| 28 | +from .select import select_example, selection_list_example |
| 29 | +from .switch import switch_example |
| 30 | + |
| 31 | + |
| 32 | +def directory_tree_example(id: str) -> ComposeResult: |
| 33 | + yield Container(DirectoryTree("./"), id=id) |
| 34 | + |
| 35 | + |
| 36 | +def footer_example(id: str) -> ComposeResult: |
| 37 | + yield Container(Footer(), id=id) |
| 38 | + |
| 39 | + |
| 40 | +def header_example(id: str) -> ComposeResult: |
| 41 | + yield Container(Header(), id=id) |
| 42 | + |
| 43 | + |
| 44 | +def input_example(id: str) -> ComposeResult: |
| 45 | + yield Container( |
| 46 | + Input(placeholder="First Name"), Input(placeholder="Last Name"), id=id |
| 47 | + ) |
| 48 | + |
| 49 | + |
| 50 | +def label_example(id: str) -> ComposeResult: |
| 51 | + yield Container(Label("Hello, world!"), id=id) |
| 52 | + |
| 53 | + |
| 54 | +def list_item_example(id: str) -> ComposeResult: |
| 55 | + yield Container( |
| 56 | + ListView( |
| 57 | + ListItem(Label("One")), |
| 58 | + ListItem(Label("Two")), |
| 59 | + ListItem(Label("Three")), |
| 60 | + ), |
| 61 | + id=id, |
| 62 | + ) |
| 63 | + |
| 64 | + yield Footer() |
| 65 | + |
| 66 | + |
| 67 | +def loading_example(id: str) -> ComposeResult: |
| 68 | + yield Container(LoadingIndicator(), id=id) |
| 69 | + |
| 70 | + |
| 71 | +def sparkline_example(id: str) -> ComposeResult: |
| 72 | + data = [random.expovariate(1 / 3) for _ in range(1000)] |
| 73 | + |
| 74 | + yield Container( |
| 75 | + Sparkline(data, summary_function=max), |
| 76 | + Sparkline(data, summary_function=mean), |
| 77 | + Sparkline(data, summary_function=min), |
| 78 | + id=id, |
| 79 | + ) |
| 80 | + |
| 81 | + |
| 82 | +def static_example(id: str) -> ComposeResult: |
| 83 | + yield Container(Static("Hello, world!"), id=id) |
| 84 | + |
| 85 | + |
| 86 | +def tree_example(id: str) -> ComposeResult: |
| 87 | + tree: Tree[dict] = Tree("Dune") |
| 88 | + tree.root.expand() |
| 89 | + characters = tree.root.add("Characters", expand=True) |
| 90 | + characters.add_leaf("Paul") |
| 91 | + characters.add_leaf("Jessica") |
| 92 | + characters.add_leaf("Chani") |
| 93 | + yield Container(tree, id=id) |
| 94 | + |
| 95 | + |
| 96 | +__all__ = [ |
| 97 | + "button_example", |
| 98 | + "checkbox_example", |
| 99 | + "data_table_example", |
| 100 | + "directory_tree_example", |
| 101 | + "footer_example", |
| 102 | + "header_example", |
| 103 | + "input_example", |
| 104 | + "label_example", |
| 105 | + "list_item_example", |
| 106 | + "loading_example", |
| 107 | + "markdown_viewer_example", |
| 108 | + "markdown_example", |
| 109 | + "option_list_example", |
| 110 | + "placeholder_example", |
| 111 | + "pretty_example", |
| 112 | + "radio_button_example", |
| 113 | + "radio_set_example", |
| 114 | + "select_example", |
| 115 | + "selection_list_example", |
| 116 | + "sparkline_example", |
| 117 | + "static_example", |
| 118 | + "switch_example", |
| 119 | + "tree_example", |
| 120 | +] |
0 commit comments