Skip to content

Don't set zoom/pan cursor for non-navigatable axes. #19904

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 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2976,11 +2976,7 @@ def _update_cursor(self, event):
"""
Update the cursor after a mouse move event or a tool (de)activation.
"""
if not event.inaxes or not self.mode:
if self._lastCursor != cursors.POINTER:
self.set_cursor(cursors.POINTER)
self._lastCursor = cursors.POINTER
else:
if self.mode and event.inaxes and event.inaxes.get_navigate():
if (self.mode == _Mode.ZOOM
and self._lastCursor != cursors.SELECT_REGION):
self.set_cursor(cursors.SELECT_REGION)
Expand All @@ -2989,6 +2985,9 @@ def _update_cursor(self, event):
and self._lastCursor != cursors.MOVE):
self.set_cursor(cursors.MOVE)
self._lastCursor = cursors.MOVE
elif self._lastCursor != cursors.POINTER:
self.set_cursor(cursors.POINTER)
self._lastCursor = cursors.POINTER

@contextmanager
def _wait_cursor_for_draw_cm(self):
Expand Down
26 changes: 11 additions & 15 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,11 @@ class SetCursorBase(ToolBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._id_drag = None
self._cursor = None
self._current_tool = None
self._default_cursor = cursors.POINTER
self._last_cursor = self._default_cursor
self.toolmanager.toolmanager_connect('tool_added_event',
self._add_tool_cbk)

# process current tools
for tool in self.toolmanager.tools.values():
self._add_tool(tool)
Expand All @@ -243,10 +242,9 @@ def set_figure(self, figure):

def _tool_trigger_cbk(self, event):
if event.tool.toggled:
self._cursor = event.tool.cursor
self._current_tool = event.tool
else:
self._cursor = None

self._current_tool = None
self._set_cursor_cbk(event.canvasevent)

def _add_tool(self, tool):
Expand All @@ -264,16 +262,14 @@ def _add_tool_cbk(self, event):
def _set_cursor_cbk(self, event):
if not event:
return

if not getattr(event, 'inaxes', False) or not self._cursor:
if self._last_cursor != self._default_cursor:
self.set_cursor(self._default_cursor)
self._last_cursor = self._default_cursor
elif self._cursor:
cursor = self._cursor
if cursor and self._last_cursor != cursor:
self.set_cursor(cursor)
self._last_cursor = cursor
if (self._current_tool and getattr(event, "inaxes", None)
and event.inaxes.get_navigate()):
if self._last_cursor != self._current_tool.cursor:
self.set_cursor(self._current_tool.cursor)
self._last_cursor = self._current_tool.cursor
elif self._last_cursor != self._default_cursor:
self.set_cursor(self._default_cursor)
self._last_cursor = self._default_cursor

def set_cursor(self, cursor):
"""
Expand Down