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

Add widget_init parameter to magic_factory #159

Merged
merged 4 commits into from
Feb 23, 2021

Conversation

tlambert03
Copy link
Member

This closes #155 by adding a widget_init parameter to magic_factory. It expects a callable that takes a single argument which will be called with the newly created widget instance each time a widget is created by the factory.

def init(widget):
    widget.x.changed.connect(lambda e: print("you changed x"))

@magic_factory(widget_init=init)
def factory(x: int = 1):
    pass

widget = factory()
widget.x.value=4  # prints you changed x

@codecov
Copy link

codecov bot commented Feb 22, 2021

Codecov Report

Merging #159 (2ec3bcc) into master (a202022) will decrease coverage by 0.44%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #159      +/-   ##
==========================================
- Coverage   91.29%   90.85%   -0.45%     
==========================================
  Files          26       28       +2     
  Lines        2609     2723     +114     
==========================================
+ Hits         2382     2474      +92     
- Misses        227      249      +22     
Impacted Files Coverage Δ
magicgui/backends/_qtpy/widgets.py 86.79% <50.00%> (+0.24%) ⬆️
magicgui/_magicgui.py 96.22% <100.00%> (+0.87%) ⬆️
magicgui/__init__.py 60.00% <0.00%> (ø)
magicgui/application.py 80.89% <0.00%> (ø)

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 a202022...dca57ee. Read the comment docs.

@tlambert03 tlambert03 merged commit 5b794f2 into pyapp-kit:master Feb 23, 2021
@tlambert03 tlambert03 deleted the factory-init-option branch February 23, 2021 01:26
@tlambert03 tlambert03 added the enhancement New feature or request label Apr 3, 2021
@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/visualizing-feature-measurements-in-napari-using-colormaps-as-luts/51567/36

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.

Cannot connect event callbacks to MagicFactory
2 participants