mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Register callbacks at message pump level, invoke them after refresh (#607)
* Register callbacks at message pump level, invoke them after refresh * Fix a typo * Code review feedback actions * call_later callbacks invoked after refresh or on idle * Fix space key in text input * Make Widget.on_idle synchronous * Fix call_later * Rename PostScreenUpdate to InvokeCallbacks, and only fire if callbacks exist * Update type hints for InvokeLater callbacks * Update type signature of call_later callbacks, extract typevar
This commit is contained in:
@@ -193,14 +193,20 @@ class MessagePump:
|
||||
return timer
|
||||
|
||||
def call_later(self, callback: Callable, *args, **kwargs) -> None:
|
||||
"""Run a callback after processing all messages and refreshing the screen.
|
||||
"""Schedule a callback to run after all messages are processed and the screen
|
||||
has been refreshed.
|
||||
|
||||
Args:
|
||||
callback (Callable): A callable.
|
||||
"""
|
||||
self.post_message_no_wait(
|
||||
events.Callback(self, partial(callback, *args, **kwargs))
|
||||
)
|
||||
# We send the InvokeLater message to ourselves first, to ensure we've cleared
|
||||
# out anything already pending in our own queue.
|
||||
message = messages.InvokeLater(self, partial(callback, *args, **kwargs))
|
||||
self.post_message_no_wait(message)
|
||||
|
||||
def handle_invoke_later(self, message: messages.InvokeLater) -> None:
|
||||
# Forward InvokeLater message to the Screen
|
||||
self.app.screen.post_message_no_wait(message)
|
||||
|
||||
def close_messages_no_wait(self) -> None:
|
||||
"""Request the message queue to exit."""
|
||||
@@ -392,9 +398,6 @@ class MessagePump:
|
||||
return False
|
||||
return self.post_message_no_wait(message)
|
||||
|
||||
async def on_callback(self, event: events.Callback) -> None:
|
||||
await invoke(event.callback)
|
||||
|
||||
def emit_no_wait(self, message: Message) -> bool:
|
||||
if self._parent:
|
||||
return self._parent.post_message_from_child_no_wait(message)
|
||||
|
||||
Reference in New Issue
Block a user