-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
Added API to insert and remove children #814
Conversation
...instead of creating new Constraints
when removing a child, its window will be None
Hm, I can't do much to make the CI happy here. Method names such as |
I also realised that there still is an issue with the Widgets which are content, either of a window or of another widget, currently have Currently, when adding a child to a widget which does not have a container, the code falls back to the window content as container: def add_child(self, child):
# if we don't have a window, we won't have a container
if self.interface.window:
child.container = self.container or self.interface.window.content._impl As a result, it becomes a subview of the window. One should instead fall back to use the parent's content as container (i.e., the widget itself). |
And one more thing: With the current implementation of Edit: To clarify, paddings will be applied relative to the window and not the box that the widget has been added to. |
I think I tracked down the reason for ignoring the parent's padding. The origin of the child layout is not set correctly because Here is the "offending" code from def content_top(self, value):
if value != self._content_top:
self._content_top = value
for child in self.node.children:
if child.layout:
child.layout._origin_top = self.absolute_content_top Maybe I am just new to travertino and the styling approach but the code is a bit of a maze to an outsider. I have now removed the check for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks fundamentally sound. However, between this and your previous PR with adding new content, I think we're reaching a point where we need a test app in the examples folder that allows testing of these features. The sample app you've provided is more than enough - we just need something that we can use as part of release testing to validate that we haven't broken anything.
Given that you've flagged the interaction with scrollview as an edge case, it would seem appropriate to include a scrollview in that demo.
Longer term, I'd like to start merging some of these test cases into a single unified "prerelease testing app". This would be an app that can be started, and the app itself contains a clear workflow and in-GUI instructions to validate that it's operating correctly (e.g., text labels that say things like "press the button, this text should turn red" or "resize the window - the button should expand with the size of the window").
refresh automatically calls the already defined `refresh_sublayouts`
I have now added a test app that can add both an image to a box or labels to a box in a scroll container. Please consider it work in progress - the user interface is a bit vague about what will happen when pressing the buttons. The example shows that I am still struggling with the If you find some time, could you maybe have a look at it? I may be missing something obvious... |
Also, there is still one "issue" with the current implementation of One could work around this by moving the calls to determine the minimum window size from |
this fixes when adding children to widget which is the content of another (e.g. ScrollWidget) where the content dimensions would not be updated before the containing widget is refreshed
Apologies for the long wait. I have finally fixed the issue with ScrollContainer - somewhat brute-force by refreshing the entire window when adding / removing children. I have also renamed the example to Could you have another look at this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely heading in the right direction - there's some really solid clarification here in the general lifecycle of widgets and subwidgets. However, it's not quite right yet - if only because the demo app is currently raising errors for me. Some details/questions inline.
Given some of the edge cases , it might also be worth adding a "reparent" option in the demo app. I'm thinking maybe two side-by-side vertical boxes in the main layout; and once you've added the image, "reparent" moves it to the end of the list of widgets, from one box to the other. That would verify whether reparenting works, and would ensure layouts are being re-evalauted as well.
ValueError: If this node is a leaf, and cannot have children. | ||
""" | ||
if child not in self.children: | ||
super().insert(index, child) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running the demo app, this line raises errors about super() has no method insert
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR requires beeware/travertino#10 to work. That PR adds insert
and remove
methods to Node
, tests those methods, and fixes an issue where a widget's origin is not recalculated when it is added as a child.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/me facepalms. My apologies - I completely forgot about that dependency.
I have now decided that automatic reparenting on I also improved the example:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good; essentially ready for merge.
I've flagged one small potential improvement inline; the other big change that will be required is a bump on the travertino version, as this code won't work with travertino 0.12.
One other small detail: This PR is still marked as a WIP. Is there additional features/changes you were hoping to include? If not, I'll cut a travertino release, which will enable you to bump the travertino dependency, and we can merge this.
ValueError: If this node is a leaf, and cannot have children. | ||
""" | ||
if child not in self.children: | ||
super().insert(index, child) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/me facepalms. My apologies - I completely forgot about that dependency.
I've removed the WIP tag, this should be ready now. And good catch about converting the O(n) check to O(1)! |
Ah, of course the checks are failing when trying to install travertino... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - this is all looking good, and Travertino 0.1.3 is now out; so I guess it's time to merge!
Fixes #30
In addition to adding children to a widget, this PR adds methods to remove and insert them. The syntax mirrors the
remove
andinsert
syntax of Python lists.No errors are raised when attempting to remove a widget which is not a child or to insert a widget which is already a child. In addition, the method
add
has been adapted to only add new children and ignore those which are already present.This PR requires corresponding API changes to travertino, submitted here.
Currently, only the Cocoa backend has been updated.
Example code to test the new API:
PR Checklist: