-
How do you wait for the result of a modal screen before continuing? E.g. the following code does not wait:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Textual has a way to pass a callback into a screen, and have the screen return the result. It's a fairly recent addition which we've been testing out and so it still needs to be documented -- you can see an example in the PR that added the feature. To see it in action in a real application, see the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer, was able to work things out thanks to it! |
Beta Was this translation helpful? Give feedback.
-
@davep Could you tell me if there are any plans for this feature? I mean not passing a callback to the modal screen but instead just awaiting its result or somehow blocking the execution of further code until the screen closes (asyncio.Event?, asyncio.Lock?). I have some business logic separated into a SomeCommand.register_activate_callback(lambda: self.app.push_screen(LoginScreen()))
some_command = SomeCommand()
result = some_command.execute() # This is not possible since inside the execute method, LoginScreen is pushed and we can't wait till it closes (also probably that should be `await some_command.execute()`
some_further_logic(result) and instead, we handle this by implementing the SomeCommand.register_activate_callback(lambda: self.app.push_screen(LoginScreen()))
some_command = SomeCommand()
def __on_result(result, exception):
# We need to react to the result here
some_further_logic(result)
pass
some_command.observe_result() Maybe it's not a big inconvenience at the moment, but I think that waiting for the result would improve a lot. I don't think working with lots of callbacks is great. I am waiting for your reply to know what you think. |
Beta Was this translation helpful? Give feedback.
Textual has a way to pass a callback into a screen, and have the screen return the result. It's a fairly recent addition which we've been testing out and so it still needs to be documented -- you can see an example in the PR that added the feature.
To see it in action in a real application, see the
YesNo
dialog in Frogmouth and then see it being used to add a yes/no confirmation around deleting something (in this case a bookmark).