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:
darrenburns
2022-08-19 14:55:53 +01:00
committed by GitHub
parent 9eea01f5a1
commit 3749412d2f
8 changed files with 83 additions and 53 deletions

View File

@@ -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)