8000 Only set the wait cursor if the last draw was >1s ago. by anntzer · Pull Request #9672 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Only set the wait cursor if the last draw was >1s ago. #9672

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

Merged
merged 1 commit into from
May 15, 2019

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Nov 3, 2017

This avoids setting the wait cursor when panning or zooming (that
behavior was somewhat annoying), or during an animation that renders at
least one frame per second.

Rename _set_cursor to _update_cursor as it is fairly different from
set_cursor and the previous name could cause confusion. Move the
defintion of cursor-related methods to a single place.

In the case of gtk, just strip out the offending cursor related code as
the backend is deprecated and slated for removal anyways.

Fixes #9546.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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

toolbar.set_cursor(toolbar._lastCursor)
return False # finish event propagation?
with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
else ExitStack()):
Copy link
Member

Choose a reason for hiding this comment

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

self.toolbar._wait_cursor_for_draw_cm() if self.toolbar else ExitStack() happens here the second time, ExitStack is overkill for this usage, I think it would be nice to move this to a function and do not bring a contextlib2 dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a second time; this is gtk3cairo which goes through a different rendering path than the various agg backends.

Using ExitStack as a "do-nothing" context manager to optionally enter a context is explicitly mentioned in the docs: https://docs.python.org/3/library/contextlib.html#simplifying-support-for-single-optional-context-managers. contextlib2 is a new dependency only on Py2; I think this is perfectly idiomatic Py3 (and again Py2 is very low on my priority list...). It's also a pure python dependency so it's not as if installing it was particularly difficult.

Copy link
Member

Choose a reason for hiding this comment

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

In Python 3.7, there will be an explicit nullcontext() for that purpose, which is semantically more clear.
https://docs.python.org/3/library/contextlib.html#simplifying-support-for-single-optional-context-managers

Please add a comment concerning this so that we can replace it once we'll depend on 3.7+ only.

Alternatively:

try:
    from contextlib import nullcontext
except ImportError:  # python 3.6 backward compatibility
    from contextlib import ExitStack as nullcontext

@@ -399,8 +396,6 @@ def expose_event(self, widget, event):
x, y, w, h = event.area
self.window.draw_drawable (self.style.fg_gc[self.state],
self._pixmap, x, y, x, y, w, h)
if toolbar:
toolbar.set_cursor(toolbar._lastCursor)
return False # finish event propagation?
Copy link
Member

Choose a reason for hiding this comment

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

What's happened to GTK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the wait cursor on GTK. I honestly have zero interest in fixing a Py2-only backend.

@tacaswell tacaswell added this to the v2.2 milestone Nov 10, 2017
Copy link
Member
@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Add contextlib2 as a dep

@tacaswell tacaswell dismissed their stale review November 10, 2017 21:39

Missed that this was already done 🐑

@anntzer
Copy link
Contributor Author
anntzer commented Nov 10, 2017

I did actually forget to declare the dependency in a few places (docs + conda meta.yaml).
I removed declaring the dependency in build_alllocal as it's not needed to build a wheel.

@anntzer anntzer force-pushed the avoid-wait-cursor branch 2 times, most recently from 5ca2e45 to 6b26215 Compare January 10, 2018 22:15
@anntzer anntzer modified the milestones: v2.2, v2.1.2 Jan 10, 2018
@anntzer anntzer added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jan 10, 2018
@anntzer
Copy link
Contributor Author
anntzer commented Jan 10, 2018

I think this is borderline release critical for 2.1.2 (because the wait cursor turned out to be quite more an annoyance than I expected). Feel free to untag if you disagree.

@jklymak
Copy link
Member
jklymak commented Jan 15, 2018

It'll have to go to 3.0 if it can't pass the Py2.7 test 😉

@anntzer anntzer force-pushed the avoid-wait-cursor branch 2 times, most recently from d8a4539 to faa9f54 Compare January 15, 2018 20:07
@tacaswell
Copy link
Member

Can we do this without adding a dependency?

I am 👎 on adding a dependency on a bug-fix release. Maybe we should just add a a 'turn it off' escape hatch?

@anntzer
Copy link
Contributor Author
anntzer commented Jan 15, 2018

I'm fine with reverting the original wait cursor PR for now.

Or we can just vendor exitstack.

@tacaswell tacaswell modified the milestones: v2.1.2, v3.0 Jan 15, 2018
@anntzer anntzer removed the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Feb 17, 2018
@tacaswell tacaswell modified the milestones: v3.0, v3.1 Jul 15, 2018
@jklymak jklymak modified the milestones: v3.1.0, v3.2.0 Feb 11, 2019
@timhoffm
Copy link
Member
timhoffm commented M 8000 ay 12, 2019

@anntzer this should simplify now that we are py3 only. Interested in a rebase?

@anntzer anntzer force-pushed the avoid-wait-cursor branch from faa9f54 to a520fa3 Compare May 12, 2019 20:12
@anntzer
Copy link
Contributor Author
anntzer commented May 12, 2019

thanks, rebased

@anntzer anntzer force-pushed the avoid-wait-cursor branch from a520fa3 to 87272b6 Compare May 13, 2019 06:40
@QuLogic
Copy link
Member
QuLogic commented May 13, 2019

Still conflicts though.

@anntzer
Copy link
Contributor Author
anntzer commented May 13, 2019

re-rebased :)

@anntzer anntzer force-pushed the avoid-wait-cursor branch from 87272b6 to 3e9b8dc Compare May 13, 2019 21:42
toolbar.set_cursor(toolbar._lastCursor)
return False # finish event propagation?
with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
else ExitStack()):
Copy link
Member

Choose a reason for hiding this comment

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

In Python 3.7, there will be an explicit nullcontext() for that purpose, which is semantically more clear.
https://docs.python.org/3/library/contextlib.html#simplifying-support-for-single-optional-context-managers

Please add a comment concerning this so that we can replace it once we'll depend on 3.7+ only.

Alternatively:

try:
    from contextlib import nullcontext
except ImportError:  # python 3.6 backward compatibility
    from contextlib import ExitStack as nullcontext

This avoids setting the wait cursor when panning or zooming (that
behavior was somewhat annoying), or during an animation that renders at
least one frame per second.

Rename `_set_cursor` to `_update_cursor` as it is fairly different from
`set_cursor` and the previous name could cause confusion.  Move the
defintion of cursor-related methods to a single place.
@anntzer anntzer force-pushed the avoid-wait-cursor branch from 3e9b8dc to 0944dcb Compare May 14, 2019 20:50
@anntzer
Copy link
Contributor Author
anntzer commented May 14, 2019

sure, switched to nullcontext()

@timhoffm timhoffm merged commit 9b49c3c into matplotlib:master May 15, 2019
@anntzer anntzer deleted the avoid-wait-cursor branch May 15, 2019 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The busy cursor is annoying in some instances
6 participants
0