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

Enable decorator to be used on methods #56

Merged
merged 4 commits into from
Dec 19, 2020

Conversation

tlambert03
Copy link
Member

closes #53 by enabling @magicgui decorator on class methods:

class MyObject:
    def __init__(self):
        self.counter = 0

    @magicgui(auto_call=True)
    def process_image(self, sigma: float = 5):
        self.counter = self.counter + sigma
        print(self)

m = MyObject()
m.process_image  # This a FunctionGui with `m` bound to `self` when calling the method.

(see also: examples/class_method.py )

This works by adding a __get__ method to the FunctionGui class, making it a descriptor that will pass the instance from which it is called as the first argument when calling the method.

@codecov
Copy link

codecov bot commented Dec 16, 2020

Codecov Report

Merging #56 (671b3fe) into master (008b0c7) will increase coverage by 0.08%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #56      +/-   ##
==========================================
+ Coverage   77.57%   77.66%   +0.08%     
==========================================
  Files          16       16              
  Lines        1793     1831      +38     
==========================================
+ Hits         1391     1422      +31     
- Misses        402      409       +7     
Impacted Files Coverage Δ
magicgui/function_gui.py 81.30% <85.71%> (+0.86%) ⬆️
magicgui/widgets/_bases.py 77.99% <85.71%> (-0.12%) ⬇️

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 008b0c7...671b3fe. Read the comment docs.

@tlambert03 tlambert03 merged commit f846964 into pyapp-kit:master Dec 19, 2020
@tlambert03 tlambert03 deleted the method-decorator branch December 19, 2020 18:22
@tlambert03 tlambert03 mentioned this pull request Jan 13, 2021
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.

Enable magicgui decorator on class member functions
1 participant