Pushing and popping views #182
-
I've been playing around textual this week and am trying to build an app with multiple pages. I see there is a I notice there is not a corresponding If I push a view on nothing is displayed, but when I pop it off again the first view shows again. from textual.app import App, DockView
from textual import events
from textual.app import App
from textual.widgets import Placeholder
class ViewPushPop(App):
async def on_load(self, event: events.Load) -> None:
await self.bind("u", "push_view", "Push View")
await self.bind("o", "pop_view", "Pop View")
async def on_mount(self, event: events.Mount) -> None:
await self.view.dock(Placeholder(name="First"), edge="top")
async def pop_view(self) -> None:
if len(self._view_stack) > 1:
view = self._view_stack.pop()
await self.remove(view)
self.refresh()
async def action_push_view(self):
new_view = DockView()
await new_view.dock(Placeholder(name="Second"), edge="top")
await self.push_view(new_view)
async def action_pop_view(self):
await self.pop_view()
ViewPushPop.run(title="View Push/Pop App", log="/tmp/textual.log") My question is, am I going down the right path here for making multi-view apps? I've also explored clearing all widgets from the original view and drawing new ones for each page, but it feels like |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I'm afraid the view stack functionality is missing, but you have correctly deduce how it should work. Expect it in a future version... |
Beta Was this translation helpful? Give feedback.
-
@jacobtomlinson Did you find a workaround? I tried your code in an effort to debug textual (I thought I had a good understanding), but couldn't figure it out why it doesn't show up. I have also tried to swap widgets between the current view and the new view, but it also didn't work. @willmcgugan If you could give us some clue on the next steps for the view stack functionality, I would follow your leads and dig deeper. |
Beta Was this translation helpful? Give feedback.
-
Try adding a call to on_resize:
|
Beta Was this translation helpful? Give feedback.
I'm afraid the view stack functionality is missing, but you have correctly deduce how it should work. Expect it in a future version...