mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Animation callback (#683)
* Add on_complete callback to Animations * Add tests for on_complete Animation callbacks * Update __textual_animation__ signature to include callback * Support awaitable callbacks for animator on_complete * Import tidying * Update animator tests
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from rich.console import RenderableType
|
||||
from rich.panel import Panel
|
||||
|
||||
from textual import events
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.layout import Horizontal, Vertical
|
||||
from textual.widget import Widget
|
||||
|
||||
|
||||
@@ -18,37 +18,22 @@ class Box(Widget, can_focus=True):
|
||||
super().__init__(*children, id=id, classes=classes)
|
||||
|
||||
def render(self) -> RenderableType:
|
||||
return Panel("Box")
|
||||
return "Box"
|
||||
|
||||
|
||||
class JustABox(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Horizontal(
|
||||
Vertical(
|
||||
Box(id="box1", classes="box"),
|
||||
Box(id="box2", classes="box"),
|
||||
# Box(id="box3", classes="box"),
|
||||
# Box(id="box4", classes="box"),
|
||||
# Box(id="box5", classes="box"),
|
||||
# Box(id="box6", classes="box"),
|
||||
# Box(id="box7", classes="box"),
|
||||
# Box(id="box8", classes="box"),
|
||||
# Box(id="box9", classes="box"),
|
||||
# Box(id="box10", classes="box"),
|
||||
id="left_pane",
|
||||
),
|
||||
Box(id="middle_pane"),
|
||||
Vertical(
|
||||
Box(id="boxa", classes="box"),
|
||||
Box(id="boxb", classes="box"),
|
||||
Box(id="boxc", classes="box"),
|
||||
id="right_pane",
|
||||
),
|
||||
id="horizontal",
|
||||
)
|
||||
self.box = Box()
|
||||
yield self.box
|
||||
|
||||
def key_p(self):
|
||||
print(self.query("#horizontal").first().styles.layout)
|
||||
def key_a(self):
|
||||
self.animator.animate(
|
||||
self.box.styles,
|
||||
"opacity",
|
||||
value=0.0,
|
||||
duration=2.0,
|
||||
on_complete=self.box.remove,
|
||||
)
|
||||
|
||||
async def on_key(self, event: events.Key) -> None:
|
||||
await self.dispatch_key(event)
|
||||
|
||||
Reference in New Issue
Block a user