mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'main' into toggle-boxen
This commit is contained in:
26
docs/examples/events/prevent.py
Normal file
26
docs/examples/events/prevent.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Horizontal
|
||||
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:
|
||||
"""Clear the text input."""
|
||||
input = self.query_one(Input)
|
||||
with input.prevent(Input.Changed): # (1)!
|
||||
input.value = ""
|
||||
|
||||
def on_input_changed(self) -> None:
|
||||
"""Called as the user types."""
|
||||
self.bell() # (2)!
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = PreventApp()
|
||||
app.run()
|
||||
@@ -1,6 +1,6 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Container, Horizontal, Vertical
|
||||
from textual.app import ComposeResult, App
|
||||
from textual.widgets import Static, Header
|
||||
from textual.widgets import Header, Static
|
||||
|
||||
|
||||
class CombiningLayoutsExample(App):
|
||||
@@ -8,28 +8,21 @@ class CombiningLayoutsExample(App):
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header()
|
||||
yield Container(
|
||||
Vertical(
|
||||
*[Static(f"Vertical layout, child {number}") for number in range(15)],
|
||||
id="left-pane",
|
||||
),
|
||||
Horizontal(
|
||||
Static("Horizontally"),
|
||||
Static("Positioned"),
|
||||
Static("Children"),
|
||||
Static("Here"),
|
||||
id="top-right",
|
||||
),
|
||||
Container(
|
||||
Static("This"),
|
||||
Static("panel"),
|
||||
Static("is"),
|
||||
Static("using"),
|
||||
Static("grid layout!", id="bottom-right-final"),
|
||||
id="bottom-right",
|
||||
),
|
||||
id="app-grid",
|
||||
)
|
||||
with Container(id="app-grid"):
|
||||
with Vertical(id="left-pane"):
|
||||
for number in range(15):
|
||||
yield Static(f"Vertical layout, child {number}")
|
||||
with Horizontal(id="top-right"):
|
||||
yield Static("Horizontally")
|
||||
yield Static("Positioned")
|
||||
yield Static("Children")
|
||||
yield Static("Here")
|
||||
with Container(id="bottom-right"):
|
||||
yield Static("This")
|
||||
yield Static("panel")
|
||||
yield Static("is")
|
||||
yield Static("using")
|
||||
yield Static("grid layout!", id="bottom-right-final")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
21
docs/examples/guide/layout/utility_containers_using_with.py
Normal file
21
docs/examples/guide/layout/utility_containers_using_with.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Horizontal, Vertical
|
||||
from textual.widgets import Static
|
||||
|
||||
|
||||
class UtilityContainersExample(App):
|
||||
CSS_PATH = "utility_containers.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with Horizontal():
|
||||
with Vertical(classes="column"):
|
||||
yield Static("One")
|
||||
yield Static("Two")
|
||||
with Vertical(classes="column"):
|
||||
yield Static("Three")
|
||||
yield Static("Four")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = UtilityContainersExample()
|
||||
app.run()
|
||||
Reference in New Issue
Block a user