-
Notifications
You must be signed in to change notification settings - Fork 815
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
pop_until_active/get_screen can't work with "uninstalled" screens #5084
Comments
We found the following entries in the FAQ which you may find helpful:
Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review. This is an automated reply, generated by FAQtory |
As you can see from the docs, you refer to installed screens by their name. So do Please read the guide on installed screens. First paragraph. |
Yes, I know how to push the installed screen. But the issue is about the inability to pop to uninstalled screen as in the title. Installed screen will be kept in memory and I don't want some screens to work like that.
There's no way to get the screen instance from screen stack when it's not installed. Handy API like get_screen supports only installed screens. Of course I could write some custom method based on public screen_stack, but wanted to point the issue with access to screen instances stored in the stack. Textual does not help much with that. |
For anyone from the future - the "workaround" is to add a utility method to the App like: def get_screen_from_current_stack(self, screen: type[Screen[ScreenResultType]]) -> Screen[ScreenResultType]:
for current_screen in self.screen_stack:
if isinstance(current_screen, screen):
return current_screen
raise ScreenNotFoundError(f"Screen {screen} not found in stack") then it can be used like: self.app.get_screen_from_current_stack(SomeScreen).pop_until_active() Still better than implementing own |
It's common that there's no need to pass a reference to some screen between multiple screens. This way when the desired screen is not "installed", you either have to access the screen stack directly to get the screen reference, or pass the reference.
There should be a better way to access screen instances stored in the stack by their type or by string.
This works:
But I see that there is no way to use
pop_until_active
when you do not store a reference to the screen when the screen is not "installed" also.This doesn't work:
This is also not-so-good approach:
I think something like this should also work:
The text was updated successfully, but these errors were encountered: