repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
textual | docs/examples/widgets/static.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Static
class StaticApp(App):
def compose(self) -> ComposeResult:
yield Static("Hello, world!")
if __name__ == "__main__":
app = StaticApp()
app.run()
| 13 | 245 |
textual | docs/examples/widgets/progress_bar_gradient.py | .py | from textual.app import App, ComposeResult
from textual.color import Gradient
from textual.containers import Center, Middle
from textual.widgets import ProgressBar
class ProgressApp(App[None]):
"""Progress bar with a rainbow gradient."""
def compose(self) -> ComposeResult:
gradient = Gradient.from_co... | 35 | 868 |
textual | docs/examples/widgets/option_list_tables.py | .py | from __future__ import annotations
from rich.table import Table
from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, OptionList
COLONIES: tuple[tuple[str, str, str, str], ...] = (
("Aerilon", "Demeter", "1.2 Billion", "Gaoth"),
("Aquaria", "Hermes", "75,000", "None"),
("... | 44 | 1,468 |
textual | docs/examples/widgets/placeholder.py | .py | from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal, VerticalScroll
from textual.widgets import Placeholder
class PlaceholderApp(App):
CSS_PATH = "placeholder.tcss"
def compose(self) -> ComposeResult:
yield VerticalScroll(
Container(
... | 39 | 1,231 |
textual | docs/examples/widgets/text_area_custom_theme.py | .py | from rich.style import Style
from textual._text_area_theme import TextAreaTheme
from textual.app import App, ComposeResult
from textual.widgets import TextArea
TEXT = """\
# says hello
def hello(name):
print("hello" + name)
# says goodbye
def goodbye(name):
print("goodbye" + name)
"""
MY_THEME = TextAreaThe... | 43 | 1,113 |
textual | docs/examples/widgets/radio_button.py | .py | from rich.text import Text
from textual.app import App, ComposeResult
from textual.widgets import RadioButton, RadioSet
class RadioChoicesApp(App[None]):
CSS_PATH = "radio_button.tcss"
def compose(self) -> ComposeResult:
with RadioSet():
yield RadioButton("Battlestar Galactica")
... | 32 | 995 |
textual | docs/examples/widgets/toast.py | .py | from textual.app import App
class ToastApp(App[None]):
def on_mount(self) -> None:
# Show an information notification.
self.notify("It's an older code, sir, but it checks out.")
# Show a warning. Note that Textual's notification system allows
# for the use of Rich console markup.
... | 27 | 897 |
textual | docs/examples/widgets/data_table.py | .py | from textual.app import App, 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.... | 31 | 846 |
textual | docs/examples/widgets/masked_input.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Label, MaskedInput
class MaskedInputApp(App):
# (1)!
CSS = """
MaskedInput.-valid {
border: tall $success 60%;
}
MaskedInput.-valid:focus {
border: tall $success;
}
MaskedInput {
margin: 1 1;
... | 33 | 626 |
textual | docs/examples/widgets/radio_set.py | .py | from rich.text import Text
from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import RadioButton, RadioSet
class RadioChoicesApp(App[None]):
CSS_PATH = "radio_set.tcss"
def compose(self) -> ComposeResult:
with Horizontal():
# A Radio... | 47 | 1,578 |
textual | docs/examples/widgets/horizontal_rules.py | .py | from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Label, Rule
class HorizontalRulesApp(App):
CSS_PATH = "horizontal_rules.tcss"
def compose(self) -> ComposeResult:
with Vertical():
yield Label("solid (default)")
yiel... | 28 | 787 |
textual | docs/examples/widgets/clock.py | .py | from datetime import datetime
from textual.app import App, ComposeResult
from textual.widgets import Digits
class ClockApp(App):
CSS = """
Screen {
align: center middle;
}
#clock {
width: auto;
}
"""
def compose(self) -> ComposeResult:
yield Digits("", id="clock")... | 32 | 633 |
textual | docs/examples/widgets/tabs.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Footer, Label, Tabs
NAMES = [
"Paul Atreidies",
"Duke Leto Atreides",
"Lady Jessica",
"Gurney Halleck",
"Baron Vladimir Harkonnen",
"Glossu Rabban",
"Chani",
"Silgar",
]
class TabsApp(App):
"""Demonstrates the ... | 83 | 1,969 |
textual | docs/examples/widgets/button.py | .py | from textual.app import App, ComposeResult
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Button, Static
class ButtonsApp(App[str]):
CSS_PATH = "button.tcss"
def compose(self) -> ComposeResult:
yield Horizontal(
VerticalScroll(
Static... | 52 | 2,008 |
textual | docs/examples/widgets/markdown.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Markdown
EXAMPLE_MARKDOWN = """\
## Markdown
- Typography *emphasis*, **strong**, `inline code` etc.
- Headers
- Lists
- Syntax highlighted code blocks
- Tables and more
## Quotes
> I must not fear.
> > Fear is the mind-killer.
> > F... | 62 | 1,688 |
textual | docs/examples/widgets/selection_list_selections.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, SelectionList
from textual.widgets.selection_list import Selection
class SelectionListApp(App[None]):
CSS_PATH = "selection_list.tcss"
def compose(self) -> ComposeResult:
yield Header()
yield SelectionList[... | 30 | 903 |
textual | docs/examples/widgets/input.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Input
class InputApp(App):
def compose(self) -> ComposeResult:
yield Input(placeholder="First Name")
yield Input(placeholder="Last Name")
if __name__ == "__main__":
app = InputApp()
app.run()
| 14 | 295 |
textual | docs/examples/widgets/link.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Link
class LabelApp(App):
AUTO_FOCUS = None
CSS = """
Screen {
align: center middle;
}
"""
def compose(self) -> ComposeResult:
yield Link(
"Go to textualize.io",
url="https://textual... | 24 | 435 |
textual | docs/examples/widgets/list_view.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Footer, Label, ListItem, ListView
class ListViewExample(App):
CSS_PATH = "list_view.tcss"
def compose(self) -> ComposeResult:
yield ListView(
ListItem(Label("One")),
ListItem(Label("Two")),
List... | 20 | 446 |
textual | docs/examples/widgets/rich_log.py | .py | import csv
import io
from rich.syntax import Syntax
from rich.table import Table
from textual import events
from textual.app import App, ComposeResult
from textual.widgets import RichLog
CSV = """lane,swimmer,country,time
4,Joseph Schooling,Singapore,50.39
2,Michael Phelps,United States,51.14
5,Chad le Clos,South Af... | 66 | 1,746 |
textual | docs/examples/widgets/option_list_options.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, OptionList
from textual.widgets.option_list import Option
class OptionListApp(App[None]):
CSS_PATH = "option_list.tcss"
def compose(self) -> ComposeResult:
yield Header()
yield OptionList(
Optio... | 37 | 1,022 |
textual | docs/examples/widgets/sparkline_basic.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Sparkline
data = [1, 2, 2, 1, 1, 4, 3, 1, 1, 8, 8, 2] # (1)!
class SparklineBasicApp(App[None]):
CSS_PATH = "sparkline_basic.tcss"
def compose(self) -> ComposeResult:
yield Sparkline( # (2)!
data, # (3)!
... | 20 | 431 |
textual | docs/examples/widgets/data_table_labels.py | .py | from rich.text import Text
from textual.app import App, 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, "... | 35 | 1,005 |
textual | docs/examples/widgets/loading_indicator.py | .py | from textual.app import App, ComposeResult
from textual.widgets import LoadingIndicator
class LoadingApp(App):
def compose(self) -> ComposeResult:
yield LoadingIndicator()
if __name__ == "__main__":
app = LoadingApp()
app.run()
| 13 | 252 |
textual | docs/examples/widgets/checkbox.py | .py | from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Checkbox
class CheckboxApp(App[None]):
CSS_PATH = "checkbox.tcss"
def compose(self) -> ComposeResult:
with VerticalScroll():
yield Checkbox("Arrakis :sweat:")
y... | 26 | 764 |
textual | docs/examples/widgets/option_list_strings.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, OptionList
class OptionListApp(App[None]):
CSS_PATH = "option_list.tcss"
def compose(self) -> ComposeResult:
yield Header()
yield OptionList(
"Aerilon",
"Aquaria",
"Cance... | 29 | 618 |
textual | docs/examples/widgets/radio_set_changed.py | .py | from rich.text import Text
from textual.app import App, ComposeResult
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Label, RadioButton, RadioSet
class RadioSetChangedApp(App[None]):
CSS_PATH = "radio_set_changed.tcss"
def compose(self) -> ComposeResult:
with V... | 47 | 1,703 |
textual | docs/examples/widgets/content_switcher.py | .py | from textual.app import App, ComposeResult
from textual.containers import Horizontal, VerticalScroll
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 direct... | 66 | 1,939 |
textual | docs/examples/widgets/collapsible_nested.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Collapsible, Label
class CollapsibleApp(App[None]):
def compose(self) -> ComposeResult:
with Collapsible(collapsed=False):
with Collapsible():
yield Label("Hello, world.")
if __name__ == "__main__":
ap... | 15 | 355 |
textual | docs/examples/widgets/input_validation.py | .py | from textual import on
from textual.app import App, ComposeResult
from textual.validation import Function, Number, ValidationResult, Validator
from textual.widgets import Input, Label, Pretty
class InputApp(App):
# (6)!
CSS = """
Input.-valid {
border: tall $success 60%;
}
Input.-valid:foc... | 73 | 1,881 |
textual | docs/examples/widgets/selection_list_selected.py | .py | from textual import on
from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.events import Mount
from textual.widgets import Footer, Header, Pretty, SelectionList
from textual.widgets.selection_list import Selection
class SelectionListApp(App[None]):
CSS_PATH = "selecti... | 41 | 1,461 |
textual | docs/examples/widgets/progress_bar_isolated_.py | .py | from textual.app import App, ComposeResult
from textual.clock import MockClock
from textual.containers import Center, Middle
from textual.timer import Timer
from textual.widgets import Footer, ProgressBar
class IndeterminateProgressBar(App[None]):
BINDINGS = [("s", "start", "Start")]
progress_timer: Timer
... | 53 | 1,663 |
textual | docs/examples/widgets/select_from_values_widget.py | .py | from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Header, Select
LINES = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.""".splitlines()
class Select... | 27 | 652 |
textual | docs/examples/widgets/progress_bar.py | .py | from textual.app import App, ComposeResult
from textual.containers import Center, VerticalScroll
from textual.widgets import Button, Header, Input, Label, ProgressBar
class FundingProgressApp(App[None]):
CSS_PATH = "progress_bar.tcss"
TITLE = "Funding tracking"
def compose(self) -> ComposeResult:
... | 41 | 1,169 |
textual | docs/examples/widgets/collapsible_custom_symbol.py | .py | from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Collapsible, Label
class CollapsibleApp(App[None]):
def compose(self) -> ComposeResult:
with Horizontal():
with Collapsible(
collapsed_symbol=">>>",
... | 26 | 672 |
textual | docs/examples/widgets/pretty.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Pretty
DATA = {
"title": "Back to the Future",
"releaseYear": 1985,
"director": "Robert Zemeckis",
"genre": "Adventure, Comedy, Sci-Fi",
"cast": [
{"actor": "Michael J. Fox", "character": "Marty McFly"},
{"actor"... | 25 | 547 |
textual | docs/examples/widgets/select_widget.py | .py | from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Header, Select
LINES = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.""".splitlines()
class Select... | 27 | 665 |
textual | docs/examples/widgets/tabbed_content_label_color.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Label, TabbedContent, TabPane
class ColorTabsApp(App):
CSS = """
TabbedContent #--content-tab-green {
color: green;
}
TabbedContent #--content-tab-red {
color: red;
}
"""
def compose(self) -> ComposeRe... | 26 | 574 |
textual | docs/examples/widgets/switch.py | .py | from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Static, Switch
class SwitchApp(App):
def compose(self) -> ComposeResult:
yield Static("[b]Example switches\n", classes="label")
yield Horizontal(
Static("off: ", classes... | 36 | 991 |
textual | docs/examples/widgets/text_area_example.py | .py | from textual.app import App, ComposeResult
from textual.widgets import TextArea
TEXT = """\
def hello(name):
print("hello" + name)
def goodbye(name):
print("goodbye" + name)
"""
class TextAreaExample(App):
def compose(self) -> ComposeResult:
yield TextArea.code_editor(TEXT, language="python")
... | 21 | 385 |
textual | docs/examples/widgets/tree.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Tree
class TreeApp(App):
def compose(self) -> ComposeResult:
tree: Tree[str] = Tree("Dune")
tree.root.expand()
characters = tree.root.add("Characters", expand=True)
characters.add_leaf("Paul")
characters... | 19 | 460 |
textual | docs/examples/widgets/sparkline_colors.py | .py | from math import sin
from textual.app import App, ComposeResult
from textual.widgets import Sparkline
class SparklineColorsApp(App[None]):
CSS_PATH = "sparkline_colors.tcss"
def compose(self) -> ComposeResult:
nums = [abs(sin(x / 3.14)) for x in range(0, 360 * 6, 20)]
yield Sparkline(nums, s... | 27 | 979 |
textual | docs/examples/widgets/log.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Log
TEXT = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.
And when it has gone past, I will turn the inner eye to see its p... | 29 | 743 |
textual | docs/examples/widgets/digits.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Digits
class DigitApp(App):
CSS = """
Screen {
align: center middle;
}
#pi {
border: double green;
width: auto;
}
"""
def compose(self) -> ComposeResult:
yield Digits("3.141,592,653,5897... | 23 | 396 |
textual | docs/examples/widgets/progress_bar_styled.py | .py | from textual.app import App, ComposeResult
from textual.containers import Center, Middle
from textual.timer import Timer
from textual.widgets import Footer, ProgressBar
class StyledProgressBar(App[None]):
BINDINGS = [("s", "start", "Start")]
CSS_PATH = "progress_bar_styled.tcss"
progress_timer: Timer
... | 36 | 1,076 |
textual | docs/examples/widgets/select_widget_no_blank.py | .py | from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Header, Select
LINES = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear.
I will permit it to pass over me and through me.""".splitlines()
ALTERNATE_LIN... | 39 | 1,053 |
textual | docs/examples/widgets/progress_bar_isolated.py | .py | from textual.app import App, ComposeResult
from textual.containers import Center, Middle
from textual.timer import Timer
from textual.widgets import Footer, ProgressBar
class IndeterminateProgressBar(App[None]):
BINDINGS = [("s", "start", "Start")]
progress_timer: Timer
"""Timer to simulate progress happ... | 35 | 1,047 |
textual | docs/examples/widgets/vertical_rules.py | .py | from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Label, Rule
class VerticalRulesApp(App):
CSS_PATH = "vertical_rules.tcss"
def compose(self) -> ComposeResult:
with Horizontal():
yield Label("solid")
yield Rule(ori... | 28 | 917 |
textual | docs/examples/widgets/sparkline.py | .py | import random
from statistics import mean
from textual.app import App, ComposeResult
from textual.widgets import Sparkline
random.seed(73)
data = [random.expovariate(1 / 3) for _ in range(1000)]
class SparklineSummaryFunctionApp(App[None]):
CSS_PATH = "sparkline.tcss"
def compose(self) -> ComposeResult:
... | 23 | 578 |
textual | docs/examples/widgets/text_area_selection.py | .py | from textual.app import App, ComposeResult
from textual.widgets import TextArea
from textual.widgets.text_area import Selection
TEXT = """\
def hello(name):
print("hello" + name)
def goodbye(name):
print("goodbye" + name)
"""
class TextAreaSelection(App):
def compose(self) -> ComposeResult:
text... | 24 | 541 |
textual | docs/examples/widgets/data_table_sort.py | .py | from rich.text import Text
from textual.app import App, ComposeResult
from textual.widgets import DataTable, Footer
ROWS = [
("lane", "swimmer", "country", "time 1", "time 2"),
(4, "Joseph Schooling", Text("Singapore", style="italic"), 50.39, 51.84),
(2, "Michael Phelps", Text("United States", style="ital... | 93 | 3,236 |
textual | docs/examples/widgets/text_area_extended.py | .py | from textual import events
from textual.app import App, ComposeResult
from textual.widgets import TextArea
class ExtendedTextArea(TextArea):
"""A subclass of TextArea with parenthesis-closing functionality."""
def _on_key(self, event: events.Key) -> None:
if event.character == "(":
self.i... | 24 | 627 |
textual | docs/examples/widgets/selection_list_tuples.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Footer, Header, SelectionList
class SelectionListApp(App[None]):
CSS_PATH = "selection_list.tcss"
def compose(self) -> ComposeResult:
yield Header()
yield SelectionList[int]( # (1)!
("Falken's Maze", 0, True),... | 29 | 769 |
textual | docs/examples/widgets/data_table_renderables.py | .py | from rich.text import Text
from textual.app import App, 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, "... | 38 | 1,122 |
textual | docs/examples/widgets/collapsible.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Collapsible, Footer, Label, Markdown
LETO = """\
# Duke Leto I Atreides
Head of House Atreides."""
JESSICA = """
# Lady Jessica
Bene Gesserit and concubine of Leto, and mother of Paul and Alia.
"""
PAUL = """
# Paul Atreides
Son of Leto and Je... | 47 | 1,157 |
textual | docs/examples/widgets/text_area_custom_language.py | .py | from pathlib import Path
from tree_sitter_languages import get_language
from textual.app import App, ComposeResult
from textual.widgets import TextArea
java_language = get_language("java")
java_highlight_query = (Path(__file__).parent / "java_highlights.scm").read_text()
java_code = """\
class HelloWorld {
publi... | 35 | 885 |
textual | docs/examples/widgets/header_app_title.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Header
class HeaderApp(App):
def compose(self) -> ComposeResult:
yield Header()
def on_mount(self) -> None:
self.title = "Header Application"
self.sub_title = "With title and sub-title"
if __name__ == "__main__":... | 17 | 357 |
textual | docs/examples/widgets/markdown_viewer.py | .py | from textual.app import App, ComposeResult
from textual.widgets import MarkdownViewer
EXAMPLE_MARKDOWN = """\
# Markdown Viewer
This is an example of Textual's `MarkdownViewer` widget.
## Features
Markdown syntax and extensions are supported.
- Typography *emphasis*, **strong**, `inline code` etc.
- Headers
- Lis... | 71 | 2,007 |
textual | docs/examples/events/on_decorator02.py | .py | from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Button
class OnDecoratorApp(App):
CSS_PATH = "on_decorator.tcss"
def compose(self) -> ComposeResult:
"""Three buttons."""
yield Button("Bell", id="bell")
yield Button("Toggle dark", classes="... | 36 | 974 |
textual | docs/examples/events/dictionary.py | .py | import asyncio
try:
import httpx
except ImportError:
raise ImportError("Please install httpx with 'pip install httpx' ")
from rich.json import JSON
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Input, Static
class DictionaryApp(App):
... | 46 | 1,387 |
textual | docs/examples/events/on_decorator01.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Button
class OnDecoratorApp(App):
CSS_PATH = "on_decorator.tcss"
def compose(self) -> ComposeResult:
"""Three buttons."""
yield Button("Bell", id="bell")
yield Button("Toggle dark", classes="toggle dark")
y... | 29 | 849 |
textual | docs/examples/events/prevent.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Button, Input
class PreventApp(App):
"""Demonstrates `prevent` context manager."""
def compose(self) -> ComposeResult:
yield Input()
yield Button("Clear", id="clear")
def on_button_pressed(self) -> None:
"""Cl... | 26 | 636 |
textual | docs/examples/events/custom01.py | .py | from textual.app import App, ComposeResult
from textual.color import Color
from textual.message import Message
from textual.widgets import Static
class ColorButton(Static):
"""A color button."""
class Selected(Message):
"""Color selected message."""
def __init__(self, color: Color) -> None:
... | 49 | 1,423 |
textual | docs/examples/tutorial/stopwatch03.py | .py | from textual.app import App, ComposeResult
from textual.containers import HorizontalGroup, VerticalScroll
from textual.widgets import Button, Digits, Footer, Header
class TimeDisplay(Digits):
"""A widget to display elapsed time."""
class Stopwatch(HorizontalGroup):
"""A stopwatch widget."""
def compose... | 43 | 1,237 |
textual | docs/examples/tutorial/stopwatch05.py | .py | from time import monotonic
from textual.app import App, ComposeResult
from textual.containers import HorizontalGroup, VerticalScroll
from textual.reactive import reactive
from textual.widgets import Button, Digits, Footer, Header
class TimeDisplay(Digits):
"""A widget to display elapsed time."""
start_time ... | 70 | 2,199 |
textual | docs/examples/tutorial/stopwatch.py | .py | from time import monotonic
from textual.app import App, ComposeResult
from textual.containers import HorizontalGroup, VerticalScroll
from textual.reactive import reactive
from textual.widgets import Button, Digits, Footer, Header
class TimeDisplay(Digits):
"""A widget to display elapsed time."""
start_time ... | 110 | 3,453 |
textual | docs/examples/tutorial/stopwatch04.py | .py | from textual.app import App, ComposeResult
from textual.containers import HorizontalGroup, VerticalScroll
from textual.widgets import Button, Digits, Footer, Header
class TimeDisplay(Digits):
"""A widget to display elapsed time."""
class Stopwatch(HorizontalGroup):
"""A stopwatch widget."""
def on_butt... | 50 | 1,521 |
textual | docs/examples/tutorial/stopwatch02.py | .py | from textual.app import App, ComposeResult
from textual.containers import HorizontalGroup, VerticalScroll
from textual.widgets import Button, Digits, Footer, Header
class TimeDisplay(Digits):
"""A widget to display elapsed time."""
class Stopwatch(HorizontalGroup):
"""A stopwatch widget."""
def compose... | 42 | 1,203 |
textual | docs/examples/tutorial/stopwatch06.py | .py | from time import monotonic
from textual.app import App, ComposeResult
from textual.containers import HorizontalGroup, VerticalScroll
from textual.reactive import reactive
from textual.widgets import Button, Digits, Footer, Header
class TimeDisplay(Digits):
"""A widget to display elapsed time."""
start_time ... | 93 | 2,960 |
textual | docs/examples/tutorial/stopwatch01.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Footer, Header
class StopwatchApp(App):
"""A Textual app to manage stopwatches."""
BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yiel... | 25 | 624 |
textual | docs/examples/getting_started/console.py | .py | """
Simulates a screenshot of the Textual devtools
"""
from textual_dev.renderables import DevConsoleHeader
from textual.app import App
from textual.widgets import Static
class ConsoleApp(App):
def compose(self):
yield Static(DevConsoleHeader())
app = ConsoleApp()
| 17 | 283 |
textual | docs/examples/guide/structure.py | .py | from datetime import datetime
from textual.app import App
from textual.widget import Widget
class Clock(Widget):
"""A clock app."""
DEFAULT_CSS = """
Clock {
content-align: center middle;
}
"""
def on_mount(self):
self.set_interval(1, self.refresh)
def render(self):
... | 31 | 494 |
textual | docs/examples/guide/dom4.py | .py | from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal
from textual.widgets import Button, Footer, Header, Static
QUESTION = "Do you want to learn about Textual CSS?"
class ExampleApp(App):
CSS_PATH = "dom4.tcss"
def compose(self) -> ComposeResult:
yield Head... | 28 | 695 |
textual | docs/examples/guide/dom1.py | .py | from textual.app import App
class ExampleApp(App):
pass
if __name__ == "__main__":
app = ExampleApp()
app.run()
| 11 | 128 |
textual | docs/examples/guide/dom3.py | .py | from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal
from textual.widgets import Button, Footer, Header, Static
QUESTION = "Do you want to learn about Textual CSS?"
class ExampleApp(App):
def compose(self) -> ComposeResult:
yield Header()
yield Footer()
... | 26 | 667 |
textual | docs/examples/guide/dom2.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Header, Footer
class ExampleApp(App):
def compose(self) -> ComposeResult:
yield Header()
yield Footer()
if __name__ == "__main__":
app = ExampleApp()
app.run()
| 14 | 263 |
textual | docs/examples/guide/testing/rgb.py | .py | from textual import on
from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Button, Footer
class RGBApp(App):
CSS = """
Screen {
align: center middle;
}
Horizontal {
width: auto;
height: auto;
}
"""
BINDIN... | 43 | 1,049 |
textual | docs/examples/guide/testing/test_rgb.py | .py | from rgb import RGBApp
from textual.color import Color
async def test_keys(): # (1)!
"""Test pressing keys has the desired result."""
app = RGBApp()
async with app.run_test() as pilot: # (2)!
# Test pressing the R key
await pilot.press("r") # (3)!
assert app.screen.styles.backg... | 43 | 1,387 |
textual | docs/examples/guide/widgets/hello04.py | .py | from itertools import cycle
from textual.app import App, ComposeResult
from textual.widgets import Static
hellos = cycle(
[
"Hola",
"Bonjour",
"Guten tag",
"Salve",
"Nǐn hǎo",
"Olá",
"Asalaam alaikum",
"Konnichiwa",
"Anyoung haseyo",
... | 59 | 1,092 |
textual | docs/examples/guide/widgets/loading01.py | .py | from asyncio import sleep
from random import randint
from textual import work
from textual.app import App, 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... | 55 | 1,396 |
textual | docs/examples/guide/widgets/hello03.py | .py | from itertools import cycle
from textual.app import App, ComposeResult
from textual.widgets import Static
hellos = cycle(
[
"Hola",
"Bonjour",
"Guten tag",
"Salve",
"Nǐn hǎo",
"Olá",
"Asalaam alaikum",
"Konnichiwa",
"Anyoung haseyo",
... | 48 | 884 |
textual | docs/examples/guide/widgets/tooltip02.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Button
TEXT = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear."""
class TooltipApp(App):
CSS = """
Screen {
align: center middle;
}
Tooltip {
... | 32 | 643 |
textual | docs/examples/guide/widgets/hello01.py | .py | from textual.app import App, ComposeResult, RenderResult
from textual.widget import Widget
class Hello(Widget):
"""Display a greeting."""
def render(self) -> RenderResult:
return "Hello, [b]World[/b]!"
class CustomApp(App):
def compose(self) -> ComposeResult:
yield Hello()
if __name__... | 20 | 372 |
textual | docs/examples/guide/widgets/checker02.py | .py | from rich.segment import Segment
from textual.app import App, ComposeResult
from textual.strip import Strip
from textual.widget import Widget
class CheckerBoard(Widget):
"""Render an 8x8 checkerboard."""
COMPONENT_CLASSES = {
"checkerboard--white-square",
"checkerboard--black-square",
}
... | 56 | 1,353 |
textual | docs/examples/guide/widgets/counter01.py | .py | from textual.app import App, ComposeResult, RenderResult
from textual.reactive import reactive
from textual.widgets import Footer, Static
class Counter(Static, can_focus=True): # (1)!
"""A counter that can be incremented and decremented by pressing keys."""
count = reactive(0)
def render(self) -> Rende... | 28 | 630 |
textual | docs/examples/guide/widgets/fizzbuzz02.py | .py | from rich.table import Table
from textual.app import App, ComposeResult
from textual.geometry import Size
from textual.widgets import Static
class FizzBuzz(Static):
def on_mount(self) -> None:
table = Table("Number", "Fizz?", "Buzz?", expand=True)
for n in range(1, 16):
fizz = not n %... | 36 | 848 |
textual | docs/examples/guide/widgets/checker01.py | .py | from rich.segment import Segment
from rich.style import Style
from textual.app import App, ComposeResult
from textual.strip import Strip
from textual.widget import Widget
class CheckerBoard(Widget):
"""Render an 8x8 checkerboard."""
def render_line(self, y: int) -> Strip:
"""Render a line of the wid... | 44 | 1,305 |
textual | docs/examples/guide/widgets/hello02.py | .py | from textual.app import App, ComposeResult, RenderResult
from textual.widget import Widget
class Hello(Widget):
"""Display a greeting."""
def render(self) -> RenderResult:
return "Hello, [b]World[/b]!"
class CustomApp(App):
CSS_PATH = "hello02.tcss"
def compose(self) -> ComposeResult:
... | 22 | 403 |
textual | docs/examples/guide/widgets/hello06.py | .py | from itertools import cycle
from textual.app import App, ComposeResult
from textual.widgets import Static
hellos = cycle(
[
"Hola",
"Bonjour",
"Guten tag",
"Salve",
"Nǐn hǎo",
"Olá",
"Asalaam alaikum",
"Konnichiwa",
"Anyoung haseyo",
... | 48 | 968 |
textual | docs/examples/guide/widgets/tooltip01.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Button
TEXT = """I must not fear.
Fear is the mind-killer.
Fear is the little-death that brings total obliteration.
I will face my fear."""
class TooltipApp(App):
CSS = """
Screen {
align: center middle;
}
"""
def com... | 27 | 546 |
textual | docs/examples/guide/widgets/checker03.py | .py | from __future__ import annotations
from textual.app import App, ComposeResult
from textual.geometry import Size
from textual.strip import Strip
from textual.scroll_view import ScrollView
from rich.segment import Segment
class CheckerBoard(ScrollView):
COMPONENT_CLASSES = {
"checkerboard--white-square",
... | 65 | 1,915 |
textual | docs/examples/guide/widgets/checker04.py | .py | from __future__ import annotations
from textual import events
from textual.app import App, ComposeResult
from textual.geometry import Offset, Region, Size
from textual.reactive import var
from textual.strip import Strip
from textual.scroll_view import ScrollView
from rich.segment import Segment
from rich.style import... | 107 | 3,622 |
textual | docs/examples/guide/widgets/fizzbuzz01.py | .py | from rich.table import Table
from textual.app import App, ComposeResult
from textual.widgets import Static
class FizzBuzz(Static):
def on_mount(self) -> None:
table = Table("Number", "Fizz?", "Buzz?")
for n in range(1, 16):
fizz = not n % 3
buzz = not n % 5
tab... | 31 | 669 |
textual | docs/examples/guide/widgets/hello05.py | .py | from itertools import cycle
from textual.app import App, ComposeResult
from textual.widgets import Static
hellos = cycle(
[
"Hola",
"Bonjour",
"Guten tag",
"Salve",
"Nǐn hǎo",
"Olá",
"Asalaam alaikum",
"Konnichiwa",
"Anyoung haseyo",
... | 45 | 863 |
textual | docs/examples/guide/widgets/counter02.py | .py | from textual.app import App, ComposeResult, RenderResult
from textual.reactive import reactive
from textual.widgets import Footer, Static
class Counter(Static, can_focus=True):
"""A counter that can be incremented and decremented by pressing keys."""
BINDINGS = [
("up,k", "change_count(1)", "Incremen... | 36 | 851 |
textual | docs/examples/guide/reactivity/computed01.py | .py | from textual.app import App, ComposeResult
from textual.color import Color
from textual.containers import Horizontal
from textual.reactive import reactive
from textual.widgets import Input, Static
class ComputedApp(App):
CSS_PATH = "computed01.tcss"
red = reactive(0)
green = reactive(0)
blue = reacti... | 48 | 1,407 |
textual | docs/examples/guide/reactivity/world_clock01.py | .py | from datetime import datetime
from pytz import timezone
from textual.app import App, ComposeResult
from textual.reactive import reactive
from textual.widget import Widget
from textual.widgets import Digits, Label
class WorldClock(Widget):
time: reactive[datetime] = reactive(datetime.now)
def __init__(self... | 53 | 1,372 |
textual | docs/examples/guide/reactivity/world_clock03.py | .py | from datetime import datetime
from pytz import timezone
from textual.app import App, ComposeResult
from textual.reactive import reactive
from textual.widget import Widget
from textual.widgets import Digits, Label
class WorldClock(Widget):
clock_time: reactive[datetime] = reactive(datetime.now)
def __init_... | 50 | 1,377 |
textual | docs/examples/guide/reactivity/watch01.py | .py | from textual.app import App, ComposeResult
from textual.color import Color, ColorParseError
from textual.containers import Grid
from textual.reactive import reactive
from textual.widgets import Input, Static
class WatchApp(App):
CSS_PATH = "watch01.tcss"
color = reactive(Color.parse("transparent")) # (1)!
... | 34 | 1,027 |
textual | docs/examples/guide/reactivity/set_reactive02.py | .py | from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.reactive import reactive, var
from textual.widgets import Label
GREETINGS = [
"Bonjour",
"Hola",
"こんにちは",
"你好",
"안녕하세요",
"Hello",
]
class Greeter(Horizontal):
"""Display a greeting and a name... | 68 | 1,613 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.