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

feat: Pass parent to backend widget #440

Merged
merged 9 commits into from
Jul 30, 2022

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Jul 20, 2022

This PR will allow passing a parent to any magicgui widget.

@hanjinliu, this requires that custom widget types accept a parent argument and will affect you. I ran your tests to make sure they pass with this PR, and they do, but you'll see a lot of FutureWarning now. Let me know if you have any thoughts/concerns

in addition to passing parent= all the way up the widget chain, this adds a parent= argument to request_values, to allow a dialog to be associated with some other widget. parent can be either a magicgui widget or a native backend widget (if a magicgui widget, widget.native will be passed to the backend)

if isinstance(parent, Widget):
parent = parent.native
try:
self._widget = widget_type(parent=parent, **backend_kwargs)
Copy link
Member Author

Choose a reason for hiding this comment

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

👀 @hanjinliu ... this is the specific line that would break magic-class. There's a fallback to the old behavior with a warning below

@codecov
Copy link

codecov bot commented Jul 20, 2022

Codecov Report

Merging #440 (39647a8) into main (7080b2b) will increase coverage by 0.02%.
The diff coverage is 98.52%.

@@            Coverage Diff             @@
##             main     #440      +/-   ##
==========================================
+ Coverage   88.99%   89.02%   +0.02%     
==========================================
  Files          30       30              
  Lines        3944     3953       +9     
==========================================
+ Hits         3510     3519       +9     
  Misses        434      434              
Impacted Files Coverage Δ
magicgui/widgets/_bases/widget.py 87.89% <88.88%> (-0.02%) ⬇️
magicgui/backends/_qtpy/widgets.py 86.95% <100.00%> (ø)
magicgui/widgets/_bases/container_widget.py 93.12% <100.00%> (+0.03%) ⬆️
magicgui/widgets/_dialogs.py 81.81% <100.00%> (+4.54%) ⬆️

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 7080b2b...39647a8. Read the comment docs.

@hanjinliu
Copy link
Contributor

Hi @tlambert03 ,
thank you for notifying me.
I totally agree with those changes. It's quite reasonable for the backend widgets to accept any keyword inputs!
I'll see and fix my codes.

@tlambert03
Copy link
Member Author

@Czaki, would be good to get your review on this one

@tlambert03 tlambert03 requested a review from Czaki July 20, 2022 13:26
Copy link
Contributor

@Czaki Czaki left a comment

Choose a reason for hiding this comment

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

I see a big profit from this PR, but I have worries about exposing users to the Qt cleaning system. The profit from this PR is big enough to implement this. But proper information should be added to the documentation.

I also think it may be profitable to connect to destroyed signal to prepare a better error message or reinstance widget on failure.

@@ -66,6 +67,7 @@ def __init__(
visible: bool | None = None,
enabled: bool = True,
gui_only=False,
parent: Any = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

The parent is not documented in the docstring. As this is a fragile part of this PR. There should be informed that if the parent widget is removed (for example, Qt native one) then the object will be unavailable, and trying to access it may end with RuntimeError: C++ wrapped object has been destroyed.

I think that it is fragile as many magicgui users are not familiar with Qt and its errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, that's a very good point. lemme think about that

Copy link
Member Author

Choose a reason for hiding this comment

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

added docs, it's too much to tackle in this PR. An approval would be appreciated so I can merge (without having to force it)

magicgui/widgets/_dialogs.py Outdated Show resolved Hide resolved
tlambert03 and others added 2 commits July 20, 2022 10:16
Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
@tlambert03 tlambert03 merged commit a81e1ec into pyapp-kit:main Jul 30, 2022
@tlambert03 tlambert03 deleted the pass-kwargs branch July 30, 2022 11:51
@tlambert03 tlambert03 added the enhancement New feature or request label Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants