Skip to content

Dynamically adding Scenes #320

@apockill

Description

@apockill

Hi! Thank you for the wonderful library. I am building a TUI which uses tab navigation, and after reading through #271 and taking a close look at the tab demo, I realized that there may not be a way to do what I'm looking for.

Basically, I have a dynamic number of tabs. The user can create new tabs, and at the moment I'm strugling to figure out a way to add them to the list of scenes.

This seems to be a typical pattern through the samples:

def demo(screen, scene):
    scenes = [
        Scene([RootPage(screen)], -1, name="Tab1"),
        Scene([AlphaPage(screen)], -1, name="Tab2"),
        Scene([BravoPage(screen)], -1, name="Tab3"),
        Scene([CharliePage(screen)], -1, name="Tab4"),
    ]
    screen.play(scenes, stop_on_resize=True, start_scene=scene, allow_int=True)

However, short of throwing a custom exception, forcing in a newly instantiated scene, and then going back to screen.play I don't see a way to dynamically register a new scene to the list and then call raise NextScene("New scene name").

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions