-
Notifications
You must be signed in to change notification settings - Fork 47
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
User internal model for Container
, simplify ContainerWidgetProtocol
#113
Conversation
Container
, simply ContainerWidgetProtocol
Container
, simplify ContainerWidgetProtocol
Codecov Report
@@ Coverage Diff @@
## master #113 +/- ##
==========================================
+ Coverage 88.32% 88.34% +0.02%
==========================================
Files 24 24
Lines 2364 2317 -47
==========================================
- Hits 2088 2047 -41
+ Misses 276 270 -6
Continue to review full report at Codecov.
|
@@ -360,3 +358,25 @@ def f(c): | |||
assert f.c.choices == (0, 1) | |||
container.reset_choices() | |||
assert f.c.choices == (0, 1, 2) | |||
|
|||
|
|||
def test_container_indexing_with_native_mucking(): |
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.
😂
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 works! 🎉
fixes #111
After thinking about it a bit, I think this is probably the most natural solution to the conundrum I posed in https://github.com/napari/magicgui/issues/111#issuecomment-763624398 (and probably the way it should have been in the first place).
This PR creates an internal list of widgets for
Containers
, no longer relying on the backend to be the source of truth. As youappend
,insert
,pop
,remove
widgets, the backend only receives commands to add or remove widget instances, (rather than indices), and must find these in their layouts. This actually greatly simplifies the protocol required of the backend widget (at, perhaps, a very slight performance hit when removing items).With this PR, if people start mucking with the native layout, it shouldn't mess up any of public magicgui API. The burden is now on users messing with
native.layout()
to deal with any potential indexing issues with their manually added widgets.it also removes the
widget.native_layout
attribute (if you want to get to it, you must usewidget.native.layout()