Skip to content
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

Merged
merged 5 commits into from
Jan 21, 2021

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Jan 20, 2021

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 you append, 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 use widget.native.layout()

@tlambert03 tlambert03 changed the title User internal model for Container, simply ContainerWidgetProtocol User internal model for Container, simplify ContainerWidgetProtocol Jan 20, 2021
@codecov
Copy link

codecov bot commented Jan 20, 2021

Codecov Report

Merging #113 (1c9ec61) into master (b455a99) will increase coverage by 0.02%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
magicgui/widgets/_protocols.py 74.27% <ø> (+0.61%) ⬆️
magicgui/widgets/_bases/container_widget.py 93.03% <82.35%> (-2.72%) ⬇️
magicgui/backends/_qtpy/widgets.py 85.71% <100.00%> (+1.05%) ⬆️
magicgui/backends/_qtpy/application.py 88.88% <0.00%> (-2.78%) ⬇️
magicgui/widgets/_concrete.py 81.74% <0.00%> (-0.80%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b455a99...8dbc909. Read the comment docs.

@@ -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():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂

Copy link
Contributor

@jni jni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works! 🎉

@tlambert03 tlambert03 merged commit 4b64773 into pyapp-kit:master Jan 21, 2021
@tlambert03 tlambert03 deleted the fix-native-widgets branch January 21, 2021 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding stretch to a widget's native layout causes a crash
2 participants