Files
textual/sandbox/darren/just_a_box.py
darrenburns 3749412d2f 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
2022-08-19 14:55:53 +01:00

45 lines
1018 B
Python

from __future__ import annotations
import asyncio
from rich.console import RenderableType
from textual import events
from textual.app import App, ComposeResult
from textual.widget import Widget
class Box(Widget, can_focus=True):
CSS = "#box {background: blue;}"
def __init__(
self, id: str | None = None, classes: str | None = None, *children: Widget
):
super().__init__(*children, id=id, classes=classes)
def render(self) -> RenderableType:
return "Box"
class JustABox(App):
def compose(self) -> ComposeResult:
self.box = Box()
yield self.box
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)
if __name__ == "__main__":
app = JustABox(css_path="just_a_box.css", watch_css=True)
app.run()