From ac0169c09423a36a2900c322e41509ecd5fd5169 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 15 Sep 2023 13:53:06 +0100 Subject: [PATCH 1/2] Use active message pump in pop screen --- src/textual/app.py | 4 +--- src/textual/screen.py | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/textual/app.py b/src/textual/app.py index 959ba3cce8..3a9bf42a5e 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -1783,9 +1783,7 @@ def push_screen( self.screen.post_message(events.ScreenSuspend()) self.screen.refresh() next_screen, await_mount = self._get_screen(screen) - next_screen._push_result_callback( - self.screen if self._screen_stack else None, callback - ) + next_screen._push_result_callback(active_message_pump.get(), callback) self._load_screen_css(next_screen) self._screen_stack.append(next_screen) self.stylesheet.update(next_screen) diff --git a/src/textual/screen.py b/src/textual/screen.py index 951cc76d4d..d0bb45cf0c 100644 --- a/src/textual/screen.py +++ b/src/textual/screen.py @@ -72,7 +72,7 @@ class ResultCallback(Generic[ScreenResultType]): def __init__( self, - requester: Widget | None, + requester: MessagePump, callback: ScreenResultCallbackType[ScreenResultType] | None, ) -> None: """Initialise the result callback object. @@ -81,7 +81,7 @@ def __init__( requester: The object making a request for the callback. callback: The callback function. """ - self.requester: Widget | None = requester + self.requester = requester """The object in the DOM that requested the callback.""" self.callback: ScreenResultCallbackType | None = callback """The callback function.""" @@ -685,7 +685,7 @@ def _invoke_later(self, callback: CallbackType, sender: MessagePump) -> None: def _push_result_callback( self, - requester: Widget | None, + requester: MessagePump, callback: ScreenResultCallbackType[ScreenResultType] | None, ) -> None: """Add a result callback to the screen. From 6c075ef33d4d6b987a07c16ace222b39b8496e77 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 15 Sep 2023 13:59:38 +0100 Subject: [PATCH 2/2] message pump --- CHANGELOG.md | 1 + src/textual/app.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c12c316f8..994f007fd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed a crash when removing an option from an `OptionList` while the mouse is hovering over the last option https://github.com/Textualize/textual/issues/3270 - Fixed a crash in `MarkdownViewer` when clicking on a link that contains an anchor https://github.com/Textualize/textual/issues/3094 +- Fixed wrong message pump in pop_screen https://github.com/Textualize/textual/pull/3315 ### Changed diff --git a/src/textual/app.py b/src/textual/app.py index 3a9bf42a5e..f98d98f482 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -1783,7 +1783,11 @@ def push_screen( self.screen.post_message(events.ScreenSuspend()) self.screen.refresh() next_screen, await_mount = self._get_screen(screen) - next_screen._push_result_callback(active_message_pump.get(), callback) + try: + message_pump = active_message_pump.get() + except LookupError: + message_pump = self.app + next_screen._push_result_callback(message_pump, callback) self._load_screen_css(next_screen) self._screen_stack.append(next_screen) self.stylesheet.update(next_screen)