Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

solution: All subclasses of LocationEvent could be used in cbook.callbacks before being fully initialized - issue 15139#16948

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 5 commits intomatplotlib:masterfromStefan-Mitic:issue/15139
Jun 9, 2020

Conversation

Stefan-Mitic
Copy link
Contributor

PR Summary

Modified the call to LocationEvent.init() to be after MouseButton initialization in MouseEvent.init(). The reason for this is the error occurs because callback.process is invoked before the initialization.

MouseEvent is a subclass of LocationEvent, so it is safe to say that motion_notify_event() can be called by a child class of LocationEvent.

Issue Ref:#15139

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@tacaswelltacaswell added this to thev3.2.2 milestoneMar 30, 2020
@tacaswell
Copy link
Member

@anntzer I don't think this collides with#16931 (which will fix the same bug by not doing the processing in__init__ anymore). I think it is worth merging and backporting this fix.

Thanks for this@Stefan-Mitic ! It looks like there are a couple of un-related commits on this branch. Could you please remove them? Seehttps://matplotlib.org/devel/gitwash/development_workflow.html?highlight=rebase#rewriting-commit-history for instructions. Remember that when you push the re-written branch to github tonot do what it suggests about merging and instead usepush --force-with-lease.

@anntzer
Copy link
Contributor

I can handle the rebase, sure.

@Stefan-Mitic
Copy link
ContributorAuthor

@anntzer I don't think this collides with#16931 (which will fix the same bug by not doing the processing in__init__ anymore). I think it is worth merging and backporting this fix.

Thanks for this@Stefan-Mitic ! It looks like there are a couple of un-related commits on this branch. Could you please remove them? Seehttps://matplotlib.org/devel/gitwash/development_workflow.html?highlight=rebase#rewriting-commit-history for instructions. Remember that when you push the re-written branch to github tonot do what it suggests about merging and instead usepush --force-with-lease.

Thanks for the help@tacaswell

@QuLogic
Copy link
Member

So if I read#15139 correctly, the same thing should be done forKeyEvent?

@Stefan-Mitic
Copy link
ContributorAuthor

Yes@QuLogic, I added it toKeyEvent. Both KeyEvent and MouseEvent are LocationEvents, I think it is fine to pass those through the callback function.

@QuLogic
Copy link
Member

Can you add tests? I think it should work inlib/matplotlib/tests/test_backend_bases.py.

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

In both cases, there should be a comment why the super-init call is deferred to the end. Usually it's in the first line and there's a danger that people will move it back later, or at least are confused why it's at the end.

@Stefan-Mitic
Copy link
ContributorAuthor

Stefan-Mitic commentedApr 4, 2020
edited
Loading

@QuLogic, I'm not sure how to trigger a keypress event to invoke my callback function.
This is the code I'm trying to work with:

def test_key_event_init():    fig, ax = plt.subplots()    canvas = FigureCanvasBase(fig)    def on_key_press(event):        assert event.key == "test_key"    canvas.mpl_connect('key_press_event', on_key_press)    # TODO: trigger key_press_event here

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@tacaswell
Copy link
Member

Given this explanation, I'm not 100% sure that this change is the correct solution.init calling other methods that rely on a fully set-up object can be problematic (as this issue illustrates).

I don't disagree, but we have the event system we have. Withsuper() you tend to end up is cases where either you have to do your work in the subclass first and then push it up the chain or push it up the chain and then extend it on the way out. Conceptually either works ("sub classes can affect the parent code by setting state" vs "subclasses can strictlyextend the base functionality") but woe unto those who end up in code bases that do some of one and some of the other....

@QuLogicQuLogic merged commit43a4c2b intomatplotlib:masterJun 9, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestJun 9, 2020
…nt could be used in cbook.callbacks before being fully initialized - issue 15139
tacaswell added a commit that referenced this pull requestJun 10, 2020
…948-on-v3.2.xBackport PR#16948 on branch v3.2.x (solution: All subclasses of LocationEvent could be used in cbook.callbacks before being fully initialized - issue 15139)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm left review comments

@tacaswelltacaswelltacaswell approved these changes

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.2.2
Development

Successfully merging this pull request may close these issues.

5 participants
@Stefan-Mitic@tacaswell@anntzer@QuLogic@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp