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 |
|---|---|---|---|---|---|
pytorch-image-models | tests/test_data.py | .py | import torch
from timm.data import create_transform
def test_naflex_eval_patchify_can_preserve_spatial_patch_dimensions():
common_kwargs = dict(
input_size=(3, 16, 16),
is_training=False,
naflex=True,
patch_size=(2, 2),
max_seq_len=16,
patchify=True,
)
imag... | 24 | 672 |
pytorch-image-models | tests/test_checkpoint_loading.py | .py | import argparse
import inspect
import pytest
import torch
from timm.models._helpers import load_state_dict, resume_checkpoint
_HAS_WEIGHTS_ONLY = 'weights_only' in inspect.signature(torch.load).parameters
_HAS_SAFE_GLOBALS = hasattr(torch.serialization, 'safe_globals')
class _CustomPayload:
def __init__(self,... | 112 | 3,939 |
pytorch-image-models | tests/test_layers_pool.py | .py | """Tests for timm pooling layers."""
import pytest
import torch
import torch.nn as nn
import importlib
import os
torch_backend = os.environ.get('TORCH_BACKEND')
if torch_backend is not None:
importlib.import_module(torch_backend)
torch_device = os.environ.get('TORCH_DEVICE', 'cpu')
# Adaptive Avg/Max Pooling Te... | 551 | 23,152 |
pytorch-image-models | tests/test_utils.py | .py | from torch.nn.modules.batchnorm import BatchNorm2d
from torchvision.ops.misc import FrozenBatchNorm2d
import timm
import pytest
from timm.utils.model import freeze, unfreeze
from timm.utils.model import ActivationStatsHook
from timm.utils.model import extract_spp_stats
from timm.utils.model import _freeze_unfreeze
fr... | 201 | 6,192 |
wtfpython | mixed_tabs_and_spaces.py | .py | def square(x):
sum_so_far = 0
for _ in range(x):
sum_so_far += x
return sum_so_far # noqa: E999 # pylint: disable=mixed-indentation Python 3 will raise a TabError here
print(square(10))
| 8 | 205 |
wtfpython | noxfile.py | .py | from typing import TYPE_CHECKING
import nox
if TYPE_CHECKING:
from nox.sessions import Session
python_versions = ["3.9", "3.10", "3.11", "3.12", "3.13"]
@nox.session(python=python_versions, reuse_venv=True)
def tests(session: "Session") -> None:
_ = session.run("python", "snippets/2_tricky_strings.py")
| 14 | 317 |
wtfpython | snippets/2_tricky_strings.py | .py | # 1
assert id("some_string") == id("some" + "_" + "string")
assert id("some_string") == id("some_string")
# 2
a = "wtf"
b = "wtf"
assert a is b
a = "wtf!"
b = "wtf!"
assert a is b
# 3
a, b = "wtf!", "wtf!"
assert a is b
a = "wtf!"; b = "wtf!"
assert a is b
| 20 | 261 |
wtfpython | irrelevant/notebook_generator.py | .py | """
An inefficient monolithic piece of code that'll generate jupyter notebook
from the projects main README.
PS: If you are a recruiter, please don't judge me by this piece of code. I wrote it
in hurry. I know this is messy and can be simplified, but I don't want to change it
much because it just works.
Simplifictio... | 398 | 14,499 |
wtfpython | irrelevant/insert_ids.py | .py | import uuid
new_file = []
original_file = []
fname = "../README.md"
def generate_random_id_comment():
random_id = uuid.uuid4()
return f"<!-- Example ID: {random_id} --!>"
with open(fname, "r") as f:
original_file = f.readlines()
for line in original_file:
new_file.append(line)
if line.strip(... | 25 | 456 |
wtfpython | irrelevant/obsolete/parse_readme.py | .py | # -*- coding: utf-8 -*-
"""
This inefficient module would parse the README.md in the initial version of
WTFPython, and enable me to categorize and reorder a hell lot of examples with
the help of the file `add_categories` (part of which is automatically
generated).
After the refactor, this module would not work now wi... | 152 | 4,129 |
wtfpython | irrelevant/obsolete/generate_contributions.py | .py | """
This script parses the README.md and generates the table
`CONTRIBUTORS.md`.
No longer works since we've moved on contributors to CONTRIBUTORS.md entirely.
"""
import pprint
import re
import requests
regex = ("[sS]uggested by @(\S+) in \[this\]\(https:\/\/github\.com\/satwikkansal"
"\/wtf[pP]ython\/issue... | 54 | 1,532 |
textual | tools/widget_documentation.py | .py | """
Helper script to help document all widgets.
This goes through the widgets listed in textual.widgets and prints the scaffolding
for the tables that are used to document the classvars BINDINGS and COMPONENT_CLASSES.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
import textual.widgets
if ... | 80 | 2,127 |
textual | docs/blog/images/gen_inspect.py | .py | from rich import inspect
from rich.console import Console
c = Console(record=True, width=110)
f = open("foo.txt", "w")
inspect(f, console=c)
c.save_svg("inspect1.svg")
inspect(f, console=c, methods=True)
c.save_svg("inspect2.svg")
inspect(f, console=c, methods=True, help=True)
c.save_svg("inspect3.svg")
| 18 | 312 |
textual | docs/blog/snippets/2022-12-07-responsive-app-background-task/blocking01.py | .py | import time
from random import randint
from textual.app import App, ComposeResult
from textual.color import Color
from textual.containers import Grid, VerticalScroll
from textual.widget import Widget
from textual.widgets import Footer, Label
class ColourChanger(Widget): # (1)!
def on_click(self) -> None:
... | 41 | 904 |
textual | docs/blog/snippets/2022-12-07-responsive-app-background-task/nonblocking01.py | .py | import asyncio
from random import randint
from textual.app import App, ComposeResult
from textual.color import Color
from textual.containers import Grid, VerticalScroll
from textual.widget import Widget
from textual.widgets import Footer, Label
class ColourChanger(Widget):
def on_click(self) -> None:
sel... | 45 | 1,072 |
textual | docs/blog/snippets/2022-12-07-responsive-app-background-task/blocking02.py | .py | import asyncio
import time
from random import randint
from textual.app import App, ComposeResult
from textual.color import Color
from textual.containers import Grid, VerticalScroll
from textual.widget import Widget
from textual.widgets import Footer, Label
class ColourChanger(Widget):
def on_click(self) -> None:... | 45 | 1,015 |
textual | docs/examples/themes/colored_text.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Label
COLORS = ("primary", "secondary", "accent", "warning", "error", "success")
class ColoredText(App[None]):
CSS = "\n".join(f".text-{color} {{color: $text-{color};}}" for color in COLORS)
def compose(self) -> ComposeResult:
fo... | 18 | 469 |
textual | docs/examples/themes/todo_app.py | .py | from itertools import cycle
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.containers import Horizontal, Vertical
from textual.widgets import Footer, Header, Input, Label, SelectionList
class TodoList(App[None]):
CSS = """
Screen {
align: center middle;
hatch:... | 97 | 2,176 |
textual | docs/examples/themes/muted_backgrounds.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Label
COLORS = ("primary", "secondary", "accent", "warning", "error", "success")
class MutedBackgrounds(App[None]):
CSS = "\n".join(
f".text-{color} {{padding: 0 1; color: $text-{color}; background: ${color}-muted;}}"
for colo... | 21 | 561 |
textual | docs/examples/widgets/directory_tree_filtered.py | .py | from pathlib import Path
from typing import Iterable
from textual.app import App, ComposeResult
from textual.widgets import DirectoryTree
class FilteredDirectoryTree(DirectoryTree):
def filter_paths(self, paths: Iterable[Path]) -> Iterable[Path]:
return [path for path in paths if not path.name.startswith... | 21 | 512 |
textual | docs/examples/widgets/tabbed_content.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Footer, Label, Markdown, TabbedContent, TabPane
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 ... | 58 | 1,467 |
textual | docs/examples/widgets/header.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Header
class HeaderApp(App):
def compose(self) -> ComposeResult:
yield Header()
if __name__ == "__main__":
app = HeaderApp()
app.run()
| 13 | 230 |
textual | docs/examples/widgets/data_table_cursors.py | .py | from itertools import cycle
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, ... | 41 | 1,110 |
textual | docs/examples/widgets/progress_bar_styled_.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 StyledProgressBar(App[None]):
BINDINGS = [("s", "start", "Start")]
CSS_PATH = "progress_bar_styled.... | 53 | 1,693 |
textual | docs/examples/widgets/data_table_fixed.py | .py | from textual.app import App, ComposeResult
from textual.widgets import DataTable
class TableApp(App):
CSS = "DataTable {height: 1fr}"
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.focus()
table.ad... | 26 | 645 |
textual | docs/examples/widgets/input_types.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Input
class InputApp(App):
def compose(self) -> ComposeResult:
yield Input(placeholder="An integer", type="integer")
yield Input(placeholder="A number", type="number")
if __name__ == "__main__":
app = InputApp()
app.r... | 14 | 325 |
textual | docs/examples/widgets/label.py | .py | from textual.app import App, ComposeResult
from textual.widgets import Label
class LabelApp(App):
def compose(self) -> ComposeResult:
yield Label("Hello, world!")
if __name__ == "__main__":
app = LabelApp()
app.run()
| 13 | 241 |
textual | docs/examples/widgets/footer.py | .py | from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer
class FooterApp(App):
BINDINGS = [
Binding(key="q", action="quit", description="Quit the app"),
Binding(
key="question_mark",
action="help",
descrip... | 26 | 680 |
textual | docs/examples/widgets/directory_tree.py | .py | from textual.app import App, ComposeResult
from textual.widgets import DirectoryTree
class DirectoryTreeApp(App):
def compose(self) -> ComposeResult:
yield DirectoryTree("./")
if __name__ == "__main__":
app = DirectoryTreeApp()
app.run()
| 13 | 262 |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.