diff --git a/CHANGELOG.md b/CHANGELOG.md index b9f38a6ca..872e70cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Breaking change: `TreeNode` can no longer be imported from `textual.widgets`; it is now available via `from textual.widgets.tree import TreeNode`. https://github.com/Textualize/textual/pull/1637 - `Tree` now shows a (subdued) cursor for a highlighted node when focus has moved elsewhere https://github.com/Textualize/textual/issues/1471 +- `MessagePump.emit` and `MessagePump.emit_no_wait` now emit events to self instead of to the parent ### Fixed diff --git a/src/textual/message_pump.py b/src/textual/message_pump.py index d79e0764c..1f0ab546e 100644 --- a/src/textual/message_pump.py +++ b/src/textual/message_pump.py @@ -581,7 +581,7 @@ class MessagePump(metaclass=MessagePumpMeta): await invoke(event.callback) def emit_no_wait(self, message: Message) -> bool: - """Send a message to the _parent_, non async version. + """Send a message to self, non-async version. Args: message: A message object. @@ -589,13 +589,10 @@ class MessagePump(metaclass=MessagePumpMeta): Returns: True if the message was posted successfully. """ - if self._parent: - return self._parent._post_message_from_child_no_wait(message) - else: - return False + return self.post_message_no_wait(message) async def emit(self, message: Message) -> bool: - """Send a message to the _parent_. + """Send a message to self. Args: message: A message object. @@ -603,10 +600,7 @@ class MessagePump(metaclass=MessagePumpMeta): Returns: True if the message was posted successfully. """ - if self._parent: - return await self._parent._post_message_from_child(message) - else: - return False + return await self.post_message(message) # TODO: Does dispatch_key belong on message pump? async def dispatch_key(self, event: events.Key) -> bool: