Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
24.07k stars 741 forks source link

Method to add content to Content Switcher #4642

Closed willmcgugan closed 2 weeks ago

willmcgugan commented 2 weeks ago

We could use a method to add new content to a ContentSwitcher. At the moment you can call mount but you need also need to set display=False.

Something like this:

def add_content(self, content:Widget, make_current=False) -> AwaitMount:
    ...
TomJGooding commented 2 weeks ago

It looks like you've already pushed this feature to main, but perhaps before/after params similar to mount could be useful?

willmcgugan commented 2 weeks ago

Isn't that redundant, if only one child widget is ever visible at a time?

TomJGooding commented 2 weeks ago

Maybe. Perhaps I'm overthinking this, but perhaps the order of the child widgets might matter in some contexts.

 content_switcher = self.query_one(ContentSwitcher)
 first_content = content_switcher.children[0]
 content_switcher.current = first_content.id
willmcgugan commented 2 weeks ago

I think in the 99% case, the order doesn't matter. Going to leave that as a "if anyone asks" possible addition.

github-actions[bot] commented 2 weeks ago

Don't forget to star the repository!

Follow @textualizeio for Textual updates.