-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wait_for_dismiss to push_screen #3477
Conversation
Co-authored-by: Rodrigo Girão Serrão <[email protected]>
Isn't it better (definitely cleaner) to just add a new method, so you don't have to add |
@mistotebe Nothing prevents us for doing both. But awaiting the screen is more verbose. screen = QuitScreen()
await self.push_screen(screen)
result = await screen.wait_for_dismiss() Compared to: result = await self.push_screen(QuitScreen(), wait_for_dismiss=True) And callbacks still have their uses. |
If such a method existed, yes, but it appears to be missing from the PR? And sounds race-prone unless implemented correctly. My instinct would have been to add something like this instead: async def push_modal_screen+bikeshed(self, screen: ModalScreen[ScreenResultType]) -> ScreenResultType:
... |
An addition to the screens API to avoid callbacks. Adds a
wait_for_dismiss
parameter which waits for the new screen to be dismissed.It works like this:
This only works from within a worker. If not run within a worker it will raise a
NoActiveWorker
error.Without a worker, waiting on the result would cause a deadlock. But at least we can identify that and raise a helpful error.
This allows for more natural code than callbacks. For example, here's how you might use a screen to ask the user if they want to quit:
The
push_screen
has overloaded signatures, so the type checker knows that there will only be a return value whenwait_for_dismiss
is True, and it knows the type of the return -- which is nice!