mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
@@ -25,6 +25,6 @@ class EventApp(App):
|
||||
self.screen.styles.background = self.COLORS[int(event.key)]
|
||||
|
||||
|
||||
app = EventApp()
|
||||
if __name__ == "__main__":
|
||||
app = EventApp()
|
||||
app.run()
|
||||
|
||||
@@ -12,7 +12,7 @@ class QuestionApp(App[str]):
|
||||
self.exit(event.button.id)
|
||||
|
||||
|
||||
app = QuestionApp()
|
||||
if __name__ == "__main__":
|
||||
app = QuestionApp()
|
||||
reply = app.run()
|
||||
print(reply)
|
||||
|
||||
@@ -3,6 +3,8 @@ from textual.widgets import Static, Button
|
||||
|
||||
|
||||
class QuestionApp(App[str]):
|
||||
CSS_PATH = "question02.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Do you love Textual?", id="question")
|
||||
yield Button("Yes", id="yes", variant="primary")
|
||||
@@ -12,7 +14,7 @@ class QuestionApp(App[str]):
|
||||
self.exit(event.button.id)
|
||||
|
||||
|
||||
app = QuestionApp(css_path="question02.css")
|
||||
if __name__ == "__main__":
|
||||
app = QuestionApp()
|
||||
reply = app.run()
|
||||
print(reply)
|
||||
|
||||
@@ -32,7 +32,7 @@ class QuestionApp(App[str]):
|
||||
self.exit(event.button.id)
|
||||
|
||||
|
||||
app = QuestionApp()
|
||||
if __name__ == "__main__":
|
||||
app = QuestionApp()
|
||||
reply = app.run()
|
||||
print(reply)
|
||||
|
||||
@@ -9,6 +9,6 @@ class ButtonsApp(App):
|
||||
yield Button("Chani")
|
||||
|
||||
|
||||
app = ButtonsApp()
|
||||
if __name__ == "__main__":
|
||||
app = ButtonsApp()
|
||||
app.run()
|
||||
|
||||
@@ -5,6 +5,6 @@ class MyApp(App):
|
||||
pass
|
||||
|
||||
|
||||
app = MyApp()
|
||||
if __name__ == "__main__":
|
||||
app = MyApp()
|
||||
app.run()
|
||||
|
||||
@@ -10,6 +10,6 @@ class WelcomeApp(App):
|
||||
self.exit()
|
||||
|
||||
|
||||
app = WelcomeApp()
|
||||
if __name__ == "__main__":
|
||||
app = WelcomeApp()
|
||||
app.run()
|
||||
|
||||
@@ -10,6 +10,6 @@ class WelcomeApp(App):
|
||||
self.exit()
|
||||
|
||||
|
||||
app = WelcomeApp()
|
||||
if __name__ == "__main__":
|
||||
app = WelcomeApp()
|
||||
app.run()
|
||||
|
||||
@@ -1,253 +0,0 @@
|
||||
/* CSS file for basic.py */
|
||||
|
||||
|
||||
|
||||
* {
|
||||
transition: color 300ms linear, background 300ms linear;
|
||||
}
|
||||
|
||||
|
||||
*:hover {
|
||||
/* tint: 30% red;
|
||||
/* outline: heavy red; */
|
||||
}
|
||||
|
||||
App > Screen {
|
||||
|
||||
background: $surface;
|
||||
color: $text;
|
||||
layers: base sidebar;
|
||||
|
||||
color: $text;
|
||||
background: $background;
|
||||
layout: vertical;
|
||||
|
||||
overflow: hidden;
|
||||
|
||||
}
|
||||
|
||||
#tree-container {
|
||||
overflow-y: auto;
|
||||
height: 20;
|
||||
margin: 1 3;
|
||||
background: $panel;
|
||||
padding: 1 2;
|
||||
}
|
||||
|
||||
DirectoryTree {
|
||||
padding: 0 1;
|
||||
height: auto;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
DataTable {
|
||||
/*border:heavy red;*/
|
||||
/* tint: 10% green; */
|
||||
/* text-opacity: 50%; */
|
||||
padding: 1;
|
||||
margin: 1 2;
|
||||
height: 24;
|
||||
}
|
||||
|
||||
#sidebar {
|
||||
color: $text;
|
||||
background: $panel;
|
||||
dock: left;
|
||||
width: 30;
|
||||
margin-bottom: 1;
|
||||
offset-x: -100%;
|
||||
|
||||
transition: offset 500ms in_out_cubic;
|
||||
layer: sidebar;
|
||||
}
|
||||
|
||||
#sidebar.-active {
|
||||
offset-x: 0;
|
||||
}
|
||||
|
||||
#sidebar .title {
|
||||
height: 1;
|
||||
background: $primary-background-darken-1;
|
||||
color: $text-muted;
|
||||
border-right: wide $background;
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
#sidebar .user {
|
||||
height: 8;
|
||||
background: $panel-darken-1;
|
||||
color: $text-muted;
|
||||
border-right: wide $background;
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
#sidebar .content {
|
||||
background: $panel-darken-2;
|
||||
color: $text;
|
||||
border-right: wide $background;
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Tweet {
|
||||
height:12;
|
||||
width: 100%;
|
||||
margin: 0 2;
|
||||
|
||||
background: $panel;
|
||||
color: $text;
|
||||
layout: vertical;
|
||||
/* border: outer $primary; */
|
||||
padding: 1;
|
||||
border: wide $panel;
|
||||
overflow: auto;
|
||||
/* scrollbar-gutter: stable; */
|
||||
align-horizontal: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
|
||||
.scrollable {
|
||||
overflow-x: auto;
|
||||
overflow-y: scroll;
|
||||
margin: 1 2;
|
||||
height: 24;
|
||||
align-horizontal: center;
|
||||
layout: vertical;
|
||||
}
|
||||
|
||||
.code {
|
||||
height: auto;
|
||||
|
||||
}
|
||||
|
||||
|
||||
TweetHeader {
|
||||
height:1;
|
||||
background: $accent;
|
||||
color: $text
|
||||
}
|
||||
|
||||
TweetBody {
|
||||
width: 100%;
|
||||
background: $panel;
|
||||
color: $text;
|
||||
height: auto;
|
||||
padding: 0 1 0 0;
|
||||
}
|
||||
|
||||
Tweet.scroll-horizontal TweetBody {
|
||||
width: 350;
|
||||
}
|
||||
|
||||
.button {
|
||||
background: $accent;
|
||||
color: $text;
|
||||
width:20;
|
||||
height: 3;
|
||||
/* border-top: hidden $accent-darken-3; */
|
||||
border: tall $accent-darken-2;
|
||||
/* border-left: tall $accent-darken-1; */
|
||||
|
||||
|
||||
/* padding: 1 0 0 0 ; */
|
||||
|
||||
transition: background 400ms in_out_cubic, color 400ms in_out_cubic;
|
||||
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background: $accent-lighten-1;
|
||||
color: $text-disabled;
|
||||
width: 20;
|
||||
height: 3;
|
||||
border: tall $accent-darken-1;
|
||||
/* border-left: tall $accent-darken-3; */
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#footer {
|
||||
color: $text;
|
||||
background: $accent;
|
||||
height: 1;
|
||||
|
||||
content-align: center middle;
|
||||
dock:bottom;
|
||||
}
|
||||
|
||||
|
||||
#sidebar .content {
|
||||
layout: vertical
|
||||
}
|
||||
|
||||
OptionItem {
|
||||
height: 3;
|
||||
background: $panel;
|
||||
border-right: wide $background;
|
||||
border-left: blank;
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
OptionItem:hover {
|
||||
height: 3;
|
||||
color: $text;
|
||||
background: $primary-darken-1;
|
||||
/* border-top: hkey $accent2-darken-3;
|
||||
border-bottom: hkey $accent2-darken-3; */
|
||||
text-style: bold;
|
||||
border-left: outer $secondary-darken-2;
|
||||
}
|
||||
|
||||
Error {
|
||||
width: 100%;
|
||||
height:3;
|
||||
background: $error;
|
||||
color: $text;
|
||||
border-top: tall $error-darken-2;
|
||||
border-bottom: tall $error-darken-2;
|
||||
|
||||
padding: 0;
|
||||
text-style: bold;
|
||||
align-horizontal: center;
|
||||
}
|
||||
|
||||
Warning {
|
||||
width: 100%;
|
||||
height:3;
|
||||
background: $warning;
|
||||
color: $text-muted;
|
||||
border-top: tall $warning-darken-2;
|
||||
border-bottom: tall $warning-darken-2;
|
||||
|
||||
text-style: bold;
|
||||
align-horizontal: center;
|
||||
}
|
||||
|
||||
Success {
|
||||
width: 100%;
|
||||
|
||||
height:auto;
|
||||
box-sizing: border-box;
|
||||
background: $success;
|
||||
color: $text-muted;
|
||||
|
||||
border-top: hkey $success-darken-2;
|
||||
border-bottom: hkey $success-darken-2;
|
||||
|
||||
text-style: bold ;
|
||||
|
||||
align-horizontal: center;
|
||||
}
|
||||
|
||||
|
||||
.horizontal {
|
||||
layout: horizontal
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
from rich.console import RenderableType
|
||||
|
||||
from rich.syntax import Syntax
|
||||
from rich.text import Text
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.reactive import Reactive
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import Static, DataTable, DirectoryTree, Header, Footer
|
||||
from textual.layout import Container
|
||||
|
||||
CODE = '''
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def loop_first(values: Iterable[T]) -> Iterable[tuple[bool, T]]:
|
||||
"""Iterate and generate a tuple with a flag for first value."""
|
||||
iter_values = iter(values)
|
||||
try:
|
||||
value = next(iter_values)
|
||||
except StopIteration:
|
||||
return
|
||||
yield True, value
|
||||
for value in iter_values:
|
||||
yield False, value
|
||||
|
||||
|
||||
def loop_last(values: Iterable[T]) -> Iterable[tuple[bool, T]]:
|
||||
"""Iterate and generate a tuple with a flag for last value."""
|
||||
iter_values = iter(values)
|
||||
try:
|
||||
previous_value = next(iter_values)
|
||||
except StopIteration:
|
||||
return
|
||||
for value in iter_values:
|
||||
yield False, previous_value
|
||||
previous_value = value
|
||||
yield True, previous_value
|
||||
|
||||
|
||||
def loop_first_last(values: Iterable[T]) -> Iterable[tuple[bool, bool, T]]:
|
||||
"""Iterate and generate a tuple with a flag for first and last value."""
|
||||
iter_values = iter(values)
|
||||
try:
|
||||
previous_value = next(iter_values)
|
||||
except StopIteration:
|
||||
return
|
||||
first = True
|
||||
for value in iter_values:
|
||||
yield first, False, previous_value
|
||||
first = False
|
||||
previous_value = value
|
||||
yield first, True, previous_value
|
||||
'''
|
||||
|
||||
|
||||
lorem_short = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit liber a a a, volutpat nec hendrerit at, faucibus in odio. Aliquam hendrerit nibh sed quam volutpat maximus. Nullam suscipit convallis lorem quis sodales. In tristique lobortis ante et dictum. Ut at finibus ipsum."""
|
||||
lorem = (
|
||||
lorem_short
|
||||
+ """ In urna dolor, placerat et mi facilisis, congue sollicitudin massa. Phasellus felis turpis, cursus eu lectus et, porttitor malesuada augue. Sed feugiat volutpat velit, sollicitudin fringilla velit bibendum faucibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit libero, volutpat nec hendrerit at, faucibus in odio. Aliquam hendrerit nibh sed quam volutpat maximus. Nullam suscipit convallis lorem quis sodales. In tristique lobortis ante et dictum. Ut at finibus ipsum. In urna dolor, placerat et mi facilisis, congue sollicitudin massa. Phasellus felis turpis, cursus eu lectus et, porttitor malesuada augue. Sed feugiat volutpat velit, sollicitudin fringilla velit bibendum faucibus. """
|
||||
)
|
||||
|
||||
lorem_short_text = Text.from_markup(lorem_short)
|
||||
lorem_long_text = Text.from_markup(lorem * 2)
|
||||
|
||||
|
||||
class TweetHeader(Widget):
|
||||
def render(self) -> RenderableType:
|
||||
return Text("Lorem Impsum", justify="center")
|
||||
|
||||
|
||||
class TweetBody(Widget):
|
||||
short_lorem = Reactive(False)
|
||||
|
||||
def render(self) -> Text:
|
||||
return lorem_short_text if self.short_lorem else lorem_long_text
|
||||
|
||||
|
||||
class Tweet(Widget):
|
||||
pass
|
||||
|
||||
|
||||
class OptionItem(Widget):
|
||||
def render(self) -> Text:
|
||||
return Text("Option")
|
||||
|
||||
|
||||
class Error(Widget):
|
||||
def render(self) -> Text:
|
||||
return Text("This is an error message", justify="center")
|
||||
|
||||
|
||||
class Warning(Widget):
|
||||
def render(self) -> Text:
|
||||
return Text("This is a warning message", justify="center")
|
||||
|
||||
|
||||
class Success(Widget):
|
||||
def render(self) -> Text:
|
||||
return Text("This is a success message", justify="center")
|
||||
|
||||
|
||||
class BasicApp(App, css_path="basic.css"):
|
||||
"""A basic app demonstrating CSS"""
|
||||
|
||||
def on_load(self):
|
||||
"""Bind keys here."""
|
||||
self.bind("s", "toggle_class('#sidebar', '-active')", description="Sidebar")
|
||||
self.bind("d", "toggle_dark", description="Dark mode")
|
||||
self.bind("q", "quit", description="Quit")
|
||||
self.bind("f", "query_test", description="Query test")
|
||||
|
||||
def compose(self):
|
||||
yield Header()
|
||||
|
||||
table = DataTable()
|
||||
self.scroll_to_target = Tweet(TweetBody())
|
||||
|
||||
yield Container(
|
||||
Tweet(TweetBody()),
|
||||
Widget(
|
||||
Static(
|
||||
Syntax(CODE, "python", line_numbers=True, indent_guides=True),
|
||||
classes="code",
|
||||
),
|
||||
classes="scrollable",
|
||||
),
|
||||
table,
|
||||
Error(),
|
||||
Tweet(TweetBody(), classes="scrollbar-size-custom"),
|
||||
Warning(),
|
||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||
Success(),
|
||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||
)
|
||||
yield Widget(
|
||||
Widget(classes="title"),
|
||||
Widget(classes="user"),
|
||||
OptionItem(),
|
||||
OptionItem(),
|
||||
OptionItem(),
|
||||
Widget(classes="content"),
|
||||
id="sidebar",
|
||||
)
|
||||
yield Footer()
|
||||
|
||||
table.add_column("Foo", width=20)
|
||||
table.add_column("Bar", width=20)
|
||||
table.add_column("Baz", width=20)
|
||||
table.add_column("Foo", width=20)
|
||||
table.add_column("Bar", width=20)
|
||||
table.add_column("Baz", width=20)
|
||||
table.zebra_stripes = True
|
||||
for n in range(100):
|
||||
table.add_row(*[f"Cell ([b]{n}[/b], {col})" for col in range(6)])
|
||||
|
||||
def on_mount(self):
|
||||
self.sub_title = "Widget demo"
|
||||
|
||||
async def on_key(self, event) -> None:
|
||||
await self.dispatch_key(event)
|
||||
|
||||
def action_toggle_dark(self):
|
||||
self.dark = not self.dark
|
||||
|
||||
def action_query_test(self):
|
||||
query = self.query("Tweet")
|
||||
self.log(query)
|
||||
self.log(query.nodes)
|
||||
self.log(query)
|
||||
self.log(query.nodes)
|
||||
|
||||
query.set_styles("outline: outer red;")
|
||||
|
||||
query = query.exclude(".scroll-horizontal")
|
||||
self.log(query)
|
||||
self.log(query.nodes)
|
||||
|
||||
# query = query.filter(".rubbish")
|
||||
# self.log(query)
|
||||
# self.log(query.first())
|
||||
|
||||
async def key_q(self):
|
||||
await self.shutdown()
|
||||
|
||||
def key_x(self):
|
||||
self.panic(self.tree)
|
||||
|
||||
def key_escape(self):
|
||||
self.app.bell()
|
||||
|
||||
def key_t(self):
|
||||
# Pressing "t" toggles the content of the TweetBody widget, from a long "Lorem ipsum..." to a shorter one.
|
||||
tweet_body = self.query("TweetBody").first()
|
||||
tweet_body.short_lorem = not tweet_body.short_lorem
|
||||
|
||||
def key_v(self):
|
||||
self.get_child(id="content").scroll_to_widget(self.scroll_to_target)
|
||||
|
||||
def key_space(self):
|
||||
self.bell()
|
||||
|
||||
|
||||
app = BasicApp()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
||||
# from textual.geometry import Region
|
||||
# from textual.color import Color
|
||||
|
||||
# print(Region.intersection.cache_info())
|
||||
# print(Region.overlaps.cache_info())
|
||||
# print(Region.union.cache_info())
|
||||
# print(Region.split_vertical.cache_info())
|
||||
# print(Region.__contains__.cache_info())
|
||||
# from textual.css.scalar import Scalar
|
||||
|
||||
# print(Scalar.resolve_dimension.cache_info())
|
||||
|
||||
# from rich.style import Style
|
||||
# from rich.cells import cached_cell_len
|
||||
|
||||
# print(Style._add.cache_info())
|
||||
|
||||
# print(cached_cell_len.cache_info())
|
||||
@@ -43,6 +43,6 @@ class ColorApp(App):
|
||||
self.screen.styles.animate("background", message.color, duration=0.5)
|
||||
|
||||
|
||||
app = ColorApp()
|
||||
if __name__ == "__main__":
|
||||
app = ColorApp()
|
||||
app.run()
|
||||
|
||||
@@ -15,6 +15,8 @@ from textual.widgets import Static, TextInput
|
||||
class DictionaryApp(App):
|
||||
"""Searches ab dictionary API as-you-type."""
|
||||
|
||||
CSS_PATH = "dictionary.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield TextInput(placeholder="Search for a word")
|
||||
yield Vertical(Static(id="results", fluid=False), id="results-container")
|
||||
@@ -38,6 +40,6 @@ class DictionaryApp(App):
|
||||
self.query_one("#results", Static).update(JSON(results))
|
||||
|
||||
|
||||
app = DictionaryApp(css_path="dictionary.css")
|
||||
if __name__ == "__main__":
|
||||
app = DictionaryApp()
|
||||
app.run()
|
||||
|
||||
@@ -5,6 +5,6 @@ class ExampleApp(App):
|
||||
pass
|
||||
|
||||
|
||||
app = ExampleApp()
|
||||
if __name__ == "__main__":
|
||||
app = ExampleApp()
|
||||
app.run()
|
||||
|
||||
@@ -8,6 +8,6 @@ class ExampleApp(App):
|
||||
yield Footer()
|
||||
|
||||
|
||||
app = ExampleApp()
|
||||
if __name__ == "__main__":
|
||||
app = ExampleApp()
|
||||
app.run()
|
||||
|
||||
@@ -20,6 +20,6 @@ class ExampleApp(App):
|
||||
)
|
||||
|
||||
|
||||
app = ExampleApp()
|
||||
if __name__ == "__main__":
|
||||
app = ExampleApp()
|
||||
app.run()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* The top level dialog (a Container) */
|
||||
#dialog {
|
||||
margin: 4 8;
|
||||
background: $primary;
|
||||
background: $panel;
|
||||
color: $text;
|
||||
border: tall $background;
|
||||
padding: 1 2;
|
||||
|
||||
@@ -6,6 +6,8 @@ QUESTION = "Do you want to learn about Textual CSS?"
|
||||
|
||||
|
||||
class ExampleApp(App):
|
||||
CSS_PATH = "dom4.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
yield Footer()
|
||||
@@ -20,4 +22,6 @@ class ExampleApp(App):
|
||||
)
|
||||
|
||||
|
||||
app = ExampleApp(css_path="dom4.css")
|
||||
if __name__ == "__main__":
|
||||
app = ExampleApp()
|
||||
app.run()
|
||||
|
||||
@@ -3,12 +3,14 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class CenterLayoutExample(App):
|
||||
CSS_PATH = "center_layout.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", id="bottom")
|
||||
yield Static("Two", id="middle")
|
||||
yield Static("Three", id="top")
|
||||
|
||||
|
||||
app = CenterLayoutExample(css_path="center_layout.css")
|
||||
if __name__ == "__main__":
|
||||
app = CenterLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -4,6 +4,8 @@ from textual.widgets import Static, Header
|
||||
|
||||
|
||||
class CombiningLayoutsExample(App):
|
||||
CSS_PATH = "combining_layouts.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
yield layout.Container(
|
||||
@@ -38,6 +40,6 @@ class CombiningLayoutsExample(App):
|
||||
print(self.stylesheet.variables["boost-lighten-2"])
|
||||
|
||||
|
||||
app = CombiningLayoutsExample(css_path="combining_layouts.css")
|
||||
if __name__ == "__main__":
|
||||
app = CombiningLayoutsExample()
|
||||
app.run()
|
||||
|
||||
@@ -10,11 +10,13 @@ Docked widgets will not scroll out of view, making them ideal for sticky headers
|
||||
|
||||
|
||||
class DockLayoutExample(App):
|
||||
CSS_PATH = "dock_layout1_sidebar.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Sidebar", id="sidebar")
|
||||
yield Static(TEXT * 10, id="body")
|
||||
|
||||
|
||||
app = DockLayoutExample(css_path="dock_layout1_sidebar.css")
|
||||
if __name__ == "__main__":
|
||||
app = DockLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -10,12 +10,14 @@ Docked widgets will not scroll out of view, making them ideal for sticky headers
|
||||
|
||||
|
||||
class DockLayoutExample(App):
|
||||
CSS_PATH = "dock_layout2_sidebar.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Sidebar2", id="another-sidebar")
|
||||
yield Static("Sidebar1", id="sidebar")
|
||||
yield Static(TEXT * 10, id="body")
|
||||
|
||||
|
||||
app = DockLayoutExample(css_path="dock_layout2_sidebar.css")
|
||||
app = DockLayoutExample()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
||||
@@ -10,12 +10,14 @@ Docked widgets will not scroll out of view, making them ideal for sticky headers
|
||||
|
||||
|
||||
class DockLayoutExample(App):
|
||||
CSS_PATH = "dock_layout3_sidebar_header.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(id="header")
|
||||
yield Static("Sidebar1", id="sidebar")
|
||||
yield Static(TEXT * 10, id="body")
|
||||
|
||||
|
||||
app = DockLayoutExample(css_path="dock_layout3_sidebar_header.css")
|
||||
if __name__ == "__main__":
|
||||
app = DockLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,6 +3,8 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class GridLayoutExample(App):
|
||||
CSS_PATH = "grid_layout1.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
@@ -12,6 +14,6 @@ class GridLayoutExample(App):
|
||||
yield Static("Six", classes="box")
|
||||
|
||||
|
||||
app = GridLayoutExample(css_path="grid_layout1.css")
|
||||
if __name__ == "__main__":
|
||||
app = GridLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,6 +3,8 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class GridLayoutExample(App):
|
||||
CSS_PATH = "grid_layout1.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
@@ -13,6 +15,6 @@ class GridLayoutExample(App):
|
||||
yield Static("Seven", classes="box")
|
||||
|
||||
|
||||
app = GridLayoutExample(css_path="grid_layout1.css")
|
||||
if __name__ == "__main__":
|
||||
app = GridLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,6 +3,8 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class GridLayoutExample(App):
|
||||
CSS_PATH = "grid_layout3_row_col_adjust.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
@@ -12,6 +14,6 @@ class GridLayoutExample(App):
|
||||
yield Static("Six", classes="box")
|
||||
|
||||
|
||||
app = GridLayoutExample(css_path="grid_layout3_row_col_adjust.css")
|
||||
if __name__ == "__main__":
|
||||
app = GridLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,6 +3,8 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class GridLayoutExample(App):
|
||||
CSS_PATH = "grid_layout4_row_col_adjust.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
@@ -12,6 +14,6 @@ class GridLayoutExample(App):
|
||||
yield Static("Six", classes="box")
|
||||
|
||||
|
||||
app = GridLayoutExample(css_path="grid_layout4_row_col_adjust.css")
|
||||
if __name__ == "__main__":
|
||||
app = GridLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,6 +3,8 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class GridLayoutExample(App):
|
||||
CSS_PATH = "grid_layout5_col_span.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two [b](column-span: 2)", classes="box", id="two")
|
||||
@@ -12,6 +14,6 @@ class GridLayoutExample(App):
|
||||
yield Static("Six", classes="box")
|
||||
|
||||
|
||||
app = GridLayoutExample(css_path="grid_layout5_col_span.css")
|
||||
if __name__ == "__main__":
|
||||
app = GridLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,6 +3,8 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class GridLayoutExample(App):
|
||||
CSS_PATH = "grid_layout6_row_span.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two [b](column-span: 2 and row-span: 2)", classes="box", id="two")
|
||||
@@ -12,6 +14,6 @@ class GridLayoutExample(App):
|
||||
yield Static("Six", classes="box")
|
||||
|
||||
|
||||
app = GridLayoutExample(css_path="grid_layout6_row_span.css")
|
||||
app = GridLayoutExample()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
||||
@@ -3,6 +3,8 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class GridLayoutExample(App):
|
||||
CSS_PATH = "grid_layout7_gutter.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
@@ -12,6 +14,6 @@ class GridLayoutExample(App):
|
||||
yield Static("Six", classes="box")
|
||||
|
||||
|
||||
app = GridLayoutExample(css_path="grid_layout7_gutter.css")
|
||||
if __name__ == "__main__":
|
||||
app = GridLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,12 +3,14 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class HorizontalLayoutExample(App):
|
||||
CSS_PATH = "horizontal_layout.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
yield Static("Three", classes="box")
|
||||
|
||||
|
||||
app = HorizontalLayoutExample(css_path="horizontal_layout.css")
|
||||
if __name__ == "__main__":
|
||||
app = HorizontalLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,12 +3,14 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class HorizontalLayoutExample(App):
|
||||
CSS_PATH = "horizontal_layout_overflow.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
yield Static("Three", classes="box")
|
||||
|
||||
|
||||
app = HorizontalLayoutExample(css_path="horizontal_layout_overflow.css")
|
||||
if __name__ == "__main__":
|
||||
app = HorizontalLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,11 +3,13 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class LayersExample(App):
|
||||
CSS_PATH = "layers.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("box1 (layer = above)", id="box1")
|
||||
yield Static("box2 (layer = below)", id="box2")
|
||||
|
||||
|
||||
app = LayersExample(css_path="layers.css")
|
||||
if __name__ == "__main__":
|
||||
app = LayersExample()
|
||||
app.run()
|
||||
|
||||
@@ -12,6 +12,8 @@ class Box(Static):
|
||||
|
||||
|
||||
class OffsetExample(App):
|
||||
CSS_PATH = "offset.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield layout.Container(
|
||||
Box(id="box1"),
|
||||
@@ -22,6 +24,6 @@ class OffsetExample(App):
|
||||
)
|
||||
|
||||
|
||||
app = OffsetExample(css_path="offset.css")
|
||||
if __name__ == "__main__":
|
||||
app = OffsetExample()
|
||||
app.run()
|
||||
|
||||
@@ -4,6 +4,8 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class UtilityContainersExample(App):
|
||||
CSS_PATH = "utility_containers.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield layout.Horizontal(
|
||||
layout.Vertical(
|
||||
@@ -19,6 +21,6 @@ class UtilityContainersExample(App):
|
||||
)
|
||||
|
||||
|
||||
app = UtilityContainersExample(css_path="utility_containers.css")
|
||||
if __name__ == "__main__":
|
||||
app = UtilityContainersExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,12 +3,14 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class VerticalLayoutExample(App):
|
||||
CSS_PATH = "vertical_layout.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
yield Static("Three", classes="box")
|
||||
|
||||
|
||||
app = VerticalLayoutExample(css_path="vertical_layout.css")
|
||||
if __name__ == "__main__":
|
||||
app = VerticalLayoutExample()
|
||||
app.run()
|
||||
|
||||
@@ -3,12 +3,14 @@ from textual.widgets import Static
|
||||
|
||||
|
||||
class VerticalLayoutScrolledExample(App):
|
||||
CSS_PATH = "vertical_layout_scrolled.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", classes="box")
|
||||
yield Static("Two", classes="box")
|
||||
yield Static("Three", classes="box")
|
||||
|
||||
|
||||
app = VerticalLayoutScrolledExample(css_path="vertical_layout_scrolled.css")
|
||||
if __name__ == "__main__":
|
||||
app = VerticalLayoutScrolledExample()
|
||||
app.run()
|
||||
|
||||
@@ -25,6 +25,6 @@ class ClockApp(App):
|
||||
yield Clock()
|
||||
|
||||
|
||||
app = ClockApp()
|
||||
if __name__ == "__main__":
|
||||
app = ClockApp()
|
||||
app.run()
|
||||
|
||||
@@ -22,6 +22,6 @@ class BorderApp(App):
|
||||
self.widget.styles.border = ("heavy", "yellow")
|
||||
|
||||
|
||||
app = BorderApp()
|
||||
if __name__ == "__main__":
|
||||
app = BorderApp()
|
||||
app.run()
|
||||
|
||||
@@ -33,6 +33,6 @@ class BoxSizing(App):
|
||||
self.widget2.styles.box_sizing = "content-box"
|
||||
|
||||
|
||||
app = BoxSizing()
|
||||
if __name__ == "__main__":
|
||||
app = BoxSizing()
|
||||
app.run()
|
||||
|
||||
@@ -12,6 +12,6 @@ class WidgetApp(App):
|
||||
self.widget.styles.border = ("heavy", "white")
|
||||
|
||||
|
||||
app = WidgetApp()
|
||||
if __name__ == "__main__":
|
||||
app = WidgetApp()
|
||||
app.run()
|
||||
|
||||
@@ -19,6 +19,6 @@ class ColorApp(App):
|
||||
self.widget3.styles.background = Color(191, 78, 96)
|
||||
|
||||
|
||||
app = ColorApp()
|
||||
if __name__ == "__main__":
|
||||
app = ColorApp()
|
||||
app.run()
|
||||
|
||||
@@ -15,6 +15,6 @@ class ColorApp(App):
|
||||
widget.styles.background = Color(191, 78, 96, a=alpha)
|
||||
|
||||
|
||||
app = ColorApp()
|
||||
if __name__ == "__main__":
|
||||
app = ColorApp()
|
||||
app.run()
|
||||
|
||||
@@ -22,6 +22,6 @@ class DimensionsApp(App):
|
||||
self.widget.styles.height = 10
|
||||
|
||||
|
||||
app = DimensionsApp()
|
||||
if __name__ == "__main__":
|
||||
app = DimensionsApp()
|
||||
app.run()
|
||||
|
||||
@@ -22,6 +22,6 @@ class DimensionsApp(App):
|
||||
self.widget.styles.height = "auto"
|
||||
|
||||
|
||||
app = DimensionsApp()
|
||||
if __name__ == "__main__":
|
||||
app = DimensionsApp()
|
||||
app.run()
|
||||
|
||||
@@ -22,6 +22,6 @@ class DimensionsApp(App):
|
||||
self.widget.styles.height = "80%"
|
||||
|
||||
|
||||
app = DimensionsApp()
|
||||
if __name__ == "__main__":
|
||||
app = DimensionsApp()
|
||||
app.run()
|
||||
|
||||
@@ -25,6 +25,6 @@ class DimensionsApp(App):
|
||||
self.widget2.styles.height = "1fr"
|
||||
|
||||
|
||||
app = DimensionsApp()
|
||||
if __name__ == "__main__":
|
||||
app = DimensionsApp()
|
||||
app.run()
|
||||
|
||||
@@ -27,6 +27,6 @@ class MarginApp(App):
|
||||
self.widget2.styles.margin = 2
|
||||
|
||||
|
||||
app = MarginApp()
|
||||
if __name__ == "__main__":
|
||||
app = MarginApp()
|
||||
app.run()
|
||||
|
||||
@@ -22,6 +22,6 @@ class OutlineApp(App):
|
||||
self.widget.styles.outline = ("heavy", "yellow")
|
||||
|
||||
|
||||
app = OutlineApp()
|
||||
if __name__ == "__main__":
|
||||
app = OutlineApp()
|
||||
app.run()
|
||||
|
||||
@@ -22,6 +22,6 @@ class PaddingApp(App):
|
||||
self.widget.styles.padding = 2
|
||||
|
||||
|
||||
app = PaddingApp()
|
||||
if __name__ == "__main__":
|
||||
app = PaddingApp()
|
||||
app.run()
|
||||
|
||||
@@ -22,6 +22,6 @@ class PaddingApp(App):
|
||||
self.widget.styles.padding = (2, 4)
|
||||
|
||||
|
||||
app = PaddingApp()
|
||||
if __name__ == "__main__":
|
||||
app = PaddingApp()
|
||||
app.run()
|
||||
|
||||
@@ -7,6 +7,6 @@ class ScreenApp(App):
|
||||
self.screen.styles.border = ("heavy", "white")
|
||||
|
||||
|
||||
app = ScreenApp()
|
||||
if __name__ == "__main__":
|
||||
app = ScreenApp()
|
||||
app.run()
|
||||
|
||||
@@ -12,6 +12,6 @@ class WidgetApp(App):
|
||||
self.widget.styles.border = ("heavy", "white")
|
||||
|
||||
|
||||
app = WidgetApp()
|
||||
if __name__ == "__main__":
|
||||
app = WidgetApp()
|
||||
app.run()
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
Screen {
|
||||
background: darkblue;
|
||||
color: white;
|
||||
layout: vertical;
|
||||
align: center middle;
|
||||
}
|
||||
Static {
|
||||
height: auto;
|
||||
padding: 2;
|
||||
margin: 2;
|
||||
border: white;
|
||||
background: #ffffff 30%;
|
||||
content-align: center middle;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Static
|
||||
|
||||
|
||||
class TextApp(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Hello")
|
||||
yield Static("[b]World![/b]")
|
||||
|
||||
|
||||
app = TextApp(css_path="simple.css")
|
||||
@@ -71,6 +71,8 @@ class Stopwatch(Static):
|
||||
class StopwatchApp(App):
|
||||
"""A Textual app to manage stopwatches."""
|
||||
|
||||
CSS_PATH = "stopwatch.css"
|
||||
|
||||
BINDINGS = [
|
||||
("d", "toggle_dark", "Toggle dark mode"),
|
||||
("a", "add_stopwatch", "Add"),
|
||||
@@ -100,6 +102,6 @@ class StopwatchApp(App):
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
app = StopwatchApp(css_path="stopwatch.css")
|
||||
if __name__ == "__main__":
|
||||
app = StopwatchApp()
|
||||
app.run()
|
||||
|
||||
@@ -17,6 +17,6 @@ class StopwatchApp(App):
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
app = StopwatchApp()
|
||||
if __name__ == "__main__":
|
||||
app = StopwatchApp()
|
||||
app.run()
|
||||
|
||||
@@ -34,6 +34,6 @@ class StopwatchApp(App):
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
app = StopwatchApp()
|
||||
if __name__ == "__main__":
|
||||
app = StopwatchApp()
|
||||
app.run()
|
||||
|
||||
@@ -21,6 +21,7 @@ class Stopwatch(Static):
|
||||
class StopwatchApp(App):
|
||||
"""A Textual app to manage stopwatches."""
|
||||
|
||||
CSS_PATH = "stopwatch03.css"
|
||||
BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
@@ -34,6 +35,6 @@ class StopwatchApp(App):
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
app = StopwatchApp(css_path="stopwatch03.css")
|
||||
if __name__ == "__main__":
|
||||
app = StopwatchApp()
|
||||
app.run()
|
||||
|
||||
@@ -28,6 +28,7 @@ class Stopwatch(Static):
|
||||
class StopwatchApp(App):
|
||||
"""A Textual app to manage stopwatches."""
|
||||
|
||||
CSS_PATH = "stopwatch04.css"
|
||||
BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
@@ -41,6 +42,6 @@ class StopwatchApp(App):
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
app = StopwatchApp(css_path="stopwatch04.css")
|
||||
if __name__ == "__main__":
|
||||
app = StopwatchApp()
|
||||
app.run()
|
||||
|
||||
@@ -48,6 +48,7 @@ class Stopwatch(Static):
|
||||
class StopwatchApp(App):
|
||||
"""A Textual app to manage stopwatches."""
|
||||
|
||||
CSS_PATH = "stopwatch04.css"
|
||||
BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
@@ -61,6 +62,6 @@ class StopwatchApp(App):
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
app = StopwatchApp(css_path="stopwatch04.css")
|
||||
if __name__ == "__main__":
|
||||
app = StopwatchApp()
|
||||
app.run()
|
||||
|
||||
@@ -71,6 +71,7 @@ class Stopwatch(Static):
|
||||
class StopwatchApp(App):
|
||||
"""A Textual app to manage stopwatches."""
|
||||
|
||||
CSS_PATH = "stopwatch04.css"
|
||||
BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
@@ -84,6 +85,6 @@ class StopwatchApp(App):
|
||||
self.dark = not self.dark
|
||||
|
||||
|
||||
app = StopwatchApp(css_path="stopwatch04.css")
|
||||
if __name__ == "__main__":
|
||||
app = StopwatchApp()
|
||||
app.run()
|
||||
|
||||
@@ -3,7 +3,9 @@ from textual.app import App, ComposeResult
|
||||
from textual.widgets import Button, Static
|
||||
|
||||
|
||||
class ButtonsApp(App):
|
||||
class ButtonsApp(App[str]):
|
||||
CSS_PATH = "button.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield layout.Horizontal(
|
||||
layout.Vertical(
|
||||
@@ -24,11 +26,11 @@ class ButtonsApp(App):
|
||||
),
|
||||
)
|
||||
|
||||
def on_button_pressed(self, _event: Button.Pressed) -> None:
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.app.bell()
|
||||
self.exit(str(event.button))
|
||||
|
||||
|
||||
app = ButtonsApp(css_path="button.css")
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = app.run()
|
||||
app = ButtonsApp()
|
||||
print(app.run())
|
||||
|
||||
@@ -111,7 +111,7 @@ Both Header and Footer are children of the Screen object.
|
||||
|
||||
To further explore the DOM, we're going to build a simple dialog with a question and two buttons. To do this we're going import and use a few more builtin widgets:
|
||||
|
||||
- `texual.layout.Container` For our top-level dialog.
|
||||
- `textual.layout.Container` For our top-level dialog.
|
||||
- `textual.layout.Horizontal` To arrange widgets left to right.
|
||||
- `textual.widgets.Static` For simple content.
|
||||
- `textual.widgets.Button` For a clickable button.
|
||||
@@ -140,13 +140,13 @@ You may recognize some of the elements in the above screenshot, but it doesn't q
|
||||
|
||||
## CSS files
|
||||
|
||||
To add a stylesheet we pass the path to the app with the `css_path` parameter:
|
||||
To add a stylesheet set the `CSS_PATH` classvar to a relative path:
|
||||
|
||||
```python hl_lines="23"
|
||||
```python hl_lines="9"
|
||||
--8<-- "docs/examples/guide/dom4.py"
|
||||
```
|
||||
|
||||
You may have noticed that some of the constructors have additional keyword argument: `id` and `classes`. These are used by the CSS to identify parts of the DOM. We will cover these in the next section.
|
||||
You may have noticed that some of the constructors have additional keyword arguments: `id` and `classes`. These are used by the CSS to identify parts of the DOM. We will cover these in the next section.
|
||||
|
||||
Here's the CSS file we are applying:
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ The first step in building a Textual app is to import the [App][textual.app.App]
|
||||
--8<-- "docs/examples/app/simple01.py"
|
||||
```
|
||||
|
||||
|
||||
### The run method
|
||||
|
||||
To run an app we create an instance and call [run()][textual.app.App.run].
|
||||
@@ -153,9 +154,9 @@ Textual apps can reference [CSS](CSS.md) files which define how your app and wid
|
||||
|
||||
The chapter on [Textual CSS](CSS.md) describes how to use CSS in detail. For now lets look at how your app references external CSS files.
|
||||
|
||||
The following example sets the `css_path` attribute on the app:
|
||||
The following example enables loading of CSS by adding a `CSS_PATH` class variable:
|
||||
|
||||
```python title="question02.py" hl_lines="15"
|
||||
```python title="question02.py" hl_lines="6"
|
||||
--8<-- "docs/examples/app/question02.py"
|
||||
```
|
||||
|
||||
@@ -172,7 +173,9 @@ When `"question02.py"` runs it will load `"question02.css"` and update the app a
|
||||
|
||||
### Classvar CSS
|
||||
|
||||
While external CSS files are recommended for most applications, and enable some cool features like *live editing* (see below), you can also specify the CSS directly within the Python code. To do this you can set the `CSS` class variable on the app which contains the CSS content.
|
||||
While external CSS files are recommended for most applications, and enable some cool features like *live editing*, you can also specify the CSS directly within the Python code.
|
||||
|
||||
To do this set a `CSS` class variable on the app to a string containing your CSS.
|
||||
|
||||
Here's the question app with classvar CSS:
|
||||
|
||||
|
||||
@@ -118,9 +118,8 @@ class LogApp(App):
|
||||
def on_mount(self):
|
||||
self.log(self.tree)
|
||||
|
||||
app = LogApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
LogApp.run()
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ Let's look at an example which looks up word definitions from an [api](https://d
|
||||
|
||||
=== "dictionary.py"
|
||||
|
||||
```python title="dictionary.py" hl_lines="26"
|
||||
```python title="dictionary.py" hl_lines="28"
|
||||
--8<-- "docs/examples/events/dictionary.py"
|
||||
```
|
||||
=== "dictionary.css"
|
||||
|
||||
@@ -200,11 +200,11 @@ While it's possible to set all styles for an app this way, it is rarely necessar
|
||||
|
||||
Let's add a CSS file to our application.
|
||||
|
||||
```python title="stopwatch03.py" hl_lines="37"
|
||||
```python title="stopwatch03.py" hl_lines="24"
|
||||
--8<-- "docs/examples/tutorial/stopwatch03.py"
|
||||
```
|
||||
|
||||
Adding the `css_path` attribute to the app constructor tells Textual to load the following file when it starts the app:
|
||||
Adding the `CSS_PATH` class variable tells Textual to load the following file when it starts the app:
|
||||
|
||||
```sass title="stopwatch03.css"
|
||||
--8<-- "docs/examples/tutorial/stopwatch03.css"
|
||||
@@ -423,7 +423,7 @@ To add a new child widget call `mount()` on the parent. To remove a widget, call
|
||||
|
||||
Let's use these to implement adding and removing stopwatches to our app.
|
||||
|
||||
```python title="stopwatch.py" hl_lines="76-77 86-90 92-96"
|
||||
```python title="stopwatch.py" hl_lines="78-79 88-92 94-98"
|
||||
--8<-- "docs/examples/tutorial/stopwatch.py"
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user