mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix actions
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user