-
Notifications
You must be signed in to change notification settings - Fork 792
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
does not pop screens
#5166
Comments
pop_until_active
does not drop off screens
pop_until_active
does not drop off screenspop_until_active
does not pop screens
The last item in the screen stack is always the active screen. I'd be surprised if you need |
My mistake. In MRE, of course, it's about I guess I can also use modes, however, it seems too complicated in my case to have multiple screen stacks and I feel like With modes, I still need to be able to manage the screen stack and dump a few screens or restore the stack to its initial state. self.app.remove_mode("some_mode")
self.app.add_mode("some_mode", SomeScreen) However I would like it to be possible to manage screens in a better way. In the current form it seems to be insufficient for applications with multiple screens as it is quite limited. I believe that the mentioned public method should simply work as expected, and there could be additional screen management options apart from it. The above-mentioned stack clearing is a common situation even with modes, and the multiple screen pops to the expected screen offered by pop_until_active is also a non-imaginary use-case. from __future__ import annotations
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.screen import Screen
from textual.widgets import Footer, Label
class FirstScreen(Screen):
BINDINGS = [
Binding("n", "second_screen", "Second screen"),
]
def compose(self) -> ComposeResult:
yield Label("First screen. Press 'n' to go to the second screen.")
yield Footer()
def action_second_screen(self) -> None:
self.app.push_screen(SecondScreen())
class SecondScreen(Screen):
BINDINGS = [
Binding("n", "third_screen", "Third screen"),
]
def compose(self) -> ComposeResult:
yield Label("Second screen. Press 'n' to go to the third screen.")
yield Footer()
async def action_third_screen(self) -> None:
"""Going back to FirstScreen and then replacing it with the ThirdScreen"""
for screen in self.app.screen_stack:
if isinstance(screen, FirstScreen):
# self.app.get_screen works only with "installed" screens
# so we need to refer by index or do a loop like this
screen.pop_until_active()
await self.app.switch_screen(ThirdScreen())
class ThirdScreen(Screen):
def compose(self) -> ComposeResult:
yield Label("Third screen.")
yield Label(f"The screen stack looks like: {self.app.screen_stack}")
yield Label("but should be: [Screen(id='_default'), ThirdScreen()]")
class MyApp(App):
def on_mount(self) -> None:
self.push_screen(FirstScreen())
MyApp().run() |
When you call I would really like to understand why you are working with screens in this way. Without understanding what you are trying to achieve, I can't help you with a potentially better solution or confidently make changes to the API. For instance:
Why? What is in those screens? You seem to be insisting you need certain functionality that I have never needed, and nobody other than yourself and @mzebrak has requested. This suggests that A) you may have a fundamental misunderstanding regarding screens and modes, or B) I don't comprehend your use case. At this point, I don't know which is the case. Until I do, I can't make any changes to the API. This is essentially an XY Problem. So please, describe your app. What is in the screens that you are pushing? Why do you want to discard a bunch of them at once? |
Hello, consider the following MRE:
version: 0.83.0
The problem is observed in situations where the next line must have the screen stack updated using the pop_until_active method.
In general, we are looking for a simple way to clear the screen stack. As it is read-only, we do not want to modify any protected attributes. It would be great to have a method to do this, it would be very helpful in applications with an onboarding process for example.
The text was updated successfully, but these errors were encountered: