-
-
Notifications
You must be signed in to change notification settings - Fork 674
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
Add API to replace children #2301
Comments
I liked the proposal, I'm trying to do something similar, but I hadn't found anything related to this page design in the documentation, I think this proposal would help my project too |
I have some hesitation about this proposal - it seems to be predicated on the assumption that widget containers are "string like". I think it's a lot more reasonable to consider them to be "list like" - if only because of the That said, I accept that "replacing X with Y" is a common use case, and the multiple-replace case can't happen, so there's no risk in using the same API name. As part of any implementation, we should also add an |
In that case, instead of EDIT: Well, I suppose we could have them both, as they're useful in different situations. |
Agreed that |
I'm taking a look at this at the PyCon US sprint |
Add API to replace children #2301
What is the problem or limitation you are having?
Currently, if I use a multi-pages design and create multiple pages (multiple boxes containing multiple widgets), and I want to switch between these pages — between page1_box and page2_box, for example — I need to:
So, not only it's 2 steps to do 1 thing (swap out/replace a child), but I also need to know the right index for the insert, which seems cumbersome to keep track of if I plan on adding/removing a few widgets during runtime.
Describe the solution you'd like
Add a
.replace()
method to nodes, that will join the likes of.remove()
.add()
and.insert()
, so that we can:Example:
main_box.replace(page1_box, page2_box)
In other words:
Box.replace(old_child, new_child)
This pattern follows the way Python's string replace works —
str.replace(old, new)
.Describe alternatives you've considered
Add method to replace its calling node.
page1_box.replace(page2_box)
In other words:
old_child.replace(new_child)
But this seems to break the existing convention with add, remove and insert.
Additional context
No response
The text was updated successfully, but these errors were encountered: