fix actions

This commit is contained in:
Will McGugan
2021-08-13 21:32:45 +01:00
parent 7140df6418
commit 01e61d600c
2 changed files with 7 additions and 6 deletions

View File

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

View File

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