mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
docs plugin
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class Colorizer(App):
|
||||
async def on_load(self):
|
||||
await self.bind("r", "color('red')")
|
||||
await self.bind("g", "color('green')")
|
||||
await self.bind("b", "color('blue')")
|
||||
|
||||
def action_color(self, color: str) -> None:
|
||||
self.background = f"on {color}"
|
||||
|
||||
|
||||
Colorizer.run()
|
||||
@@ -1,9 +0,0 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class Quiter(App):
|
||||
async def on_load(self):
|
||||
await self.bind("q", "quit")
|
||||
|
||||
|
||||
Quiter.run()
|
||||
@@ -1,9 +0,0 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class Beeper(App):
|
||||
def on_key(self):
|
||||
self.console.bell()
|
||||
|
||||
|
||||
Beeper.run()
|
||||
@@ -1,10 +0,0 @@
|
||||
from textual.app import App
|
||||
from textual import events
|
||||
|
||||
|
||||
class Beeper(App):
|
||||
async def on_key(self, event: events.Key) -> None:
|
||||
self.console.bell()
|
||||
|
||||
|
||||
Beeper.run()
|
||||
@@ -1,10 +0,0 @@
|
||||
from textual.app import App
|
||||
|
||||
|
||||
class ColorChanger(App):
|
||||
def on_key(self, event):
|
||||
if event.key.isdigit():
|
||||
self.background = f"on color({event.key})"
|
||||
|
||||
|
||||
ColorChanger.run(log_path="textual.log")
|
||||
28
docs/examples/simple.py
Normal file
28
docs/examples/simple.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Static
|
||||
|
||||
|
||||
class TextApp(App):
|
||||
CSS = """
|
||||
Screen {
|
||||
background: darkblue;
|
||||
color: white;
|
||||
layout: vertical;
|
||||
}
|
||||
Static {
|
||||
height: auto;
|
||||
padding: 2;
|
||||
border: heavy white;
|
||||
background: #ffffff 30%;
|
||||
content-align: center middle;
|
||||
/**/
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Hello")
|
||||
yield Static("[b]World![/b]")
|
||||
|
||||
|
||||
app = TextApp()
|
||||
@@ -1,24 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from rich.align import Align
|
||||
from rich.style import Style
|
||||
|
||||
from textual.app import App
|
||||
from textual.widget import Widget
|
||||
|
||||
|
||||
class Clock(Widget):
|
||||
def on_mount(self):
|
||||
self.set_interval(1, self.refresh)
|
||||
|
||||
def render(self, style: Style):
|
||||
time = datetime.now().strftime("%c")
|
||||
return Align.center(time, vertical="middle")
|
||||
|
||||
|
||||
class ClockApp(App):
|
||||
async def on_mount(self):
|
||||
await self.screen.dock(Clock())
|
||||
|
||||
|
||||
ClockApp.run()
|
||||
@@ -1,33 +0,0 @@
|
||||
from rich.panel import Panel
|
||||
from rich.style import Style
|
||||
|
||||
from textual.app import App
|
||||
from textual.reactive import Reactive
|
||||
from textual.widget import Widget
|
||||
|
||||
|
||||
class Hover(Widget):
|
||||
|
||||
mouse_over = Reactive(False)
|
||||
|
||||
def render(self, style: Style) -> Panel:
|
||||
return Panel("Hello [b]World[/b]", style=("on red" if self.mouse_over else ""))
|
||||
|
||||
def on_enter(self) -> None:
|
||||
self.mouse_over = True
|
||||
|
||||
def on_leave(self) -> None:
|
||||
self.mouse_over = False
|
||||
|
||||
|
||||
class HoverApp(App):
|
||||
"""Demonstrates smooth animation"""
|
||||
|
||||
async def on_mount(self) -> None:
|
||||
"""Build layout here."""
|
||||
|
||||
hovers = (Hover() for _ in range(10))
|
||||
await self.screen.dock(*hovers, edge="top")
|
||||
|
||||
|
||||
HoverApp.run(log_path="textual.log")
|
||||
@@ -1,15 +0,0 @@
|
||||
from textual.app import App
|
||||
from textual.widgets import Placeholder
|
||||
|
||||
|
||||
class SimpleApp(App):
|
||||
"""Demonstrates smooth animation"""
|
||||
|
||||
async def on_mount(self) -> None:
|
||||
"""Build layout here."""
|
||||
|
||||
await self.screen.dock(Placeholder(), edge="left", size=40)
|
||||
await self.screen.dock(Placeholder(), Placeholder(), edge="top")
|
||||
|
||||
|
||||
SimpleApp.run(log_path="textual.log")
|
||||
Reference in New Issue
Block a user