From 01e61d600c23c95a52abf947d152ae63df510ccf Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 13 Aug 2021 21:32:45 +0100 Subject: [PATCH] fix actions --- examples/animation.py | 8 ++++---- src/textual/app.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/animation.py b/examples/animation.py index ea71652d6..4531e5114 100644 --- a/examples/animation.py +++ b/examples/animation.py @@ -7,18 +7,18 @@ from textual.widgets import Footer, Placeholder class SmoothApp(App): """Demonstrates smooth animation. Press 'b' to see it in action.""" - async def on_load(self, event: events.Load) -> None: + async def on_load(self) -> None: """Bind keys here.""" await self.bind("b", "toggle_sidebar", "Toggle sidebar") await self.bind("q", "quit", "Quit") - show_bar: Reactive[bool] = Reactive(False) + show_bar = Reactive(False) - async def watch_show_bar(self, show_bar: bool) -> None: + def watch_show_bar(self, show_bar: bool) -> None: """Called when show_bar changes.""" self.bar.animate("layout_offset_x", 0 if show_bar else -40) - async def action_toggle_sidebar(self) -> None: + def action_toggle_sidebar(self) -> None: """Called when user hits 'b' key.""" self.show_bar = not self.show_bar diff --git a/src/textual/app.py b/src/textual/app.py index 2e43a0b68..13d0042d8 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -19,6 +19,7 @@ from ._animator import Animator from .binding import Bindings, NoBinding from .geometry import Offset, Region from . import log +from ._callback import invoke from ._context import active_app from ._event_broker import extract_handler_actions, NoHandler from ._types import MessageTarget @@ -407,8 +408,8 @@ class App(MessagePump): _rich_traceback_guard = True method_name = f"action_{action_name}" method = getattr(namespace, method_name, None) - if method is not None: - await method(*params) + if callable(method): + await invoke(method, *params) async def broker_event( self, event_name: str, event: events.Event, default_namespace: object | None