Skip to content

Simplify 3d axes callback setup. #15855

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
Mar 9, 2020
Merged
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
29 changes: 11 additions & 18 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def __init__(

if rect is None:
rect = [0.0, 0.0, 1.0, 1.0]
self._cids = []

self.initial_azim = azim
self.initial_elev = elev
Expand Down Expand Up @@ -115,6 +114,12 @@ def __init__(
self._zcid = None

self.mouse_init()
self.figure.canvas.mpl_connect(
'motion_notify_event', self._on_move),
self.figure.canvas.mpl_connect(
'button_press_event', self._button_press),
self.figure.canvas.mpl_connect(
'button_release_event', self._button_release),
self.set_top_view()

self.patch.set_linewidth(0)
Expand Down Expand Up @@ -1004,8 +1009,7 @@ def get_proj(self):

def mouse_init(self, rotate_btn=1, zoom_btn=3):
"""
Initializes mouse button callbacks to enable 3D rotation of the axes.
Also optionally sets the mouse buttons for 3D rotation and zooming.
Set the mouse buttons for 3D rotation and zooming.

Parameters
----------
Expand All @@ -1015,20 +1019,16 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3):
The mouse button or buttons to use to zoom the 3D axes.
"""
self.button_pressed = None
self._cids = [
self.figure.canvas.mpl_connect(
'motion_notify_event', self._on_move),
self.figure.canvas.mpl_connect(
'button_press_event', self._button_press),
self.figure.canvas.mpl_connect(
'button_release_event', self._button_release),
]
# coerce scalars into array-like, then convert into
# a regular list to avoid comparisons against None
# which breaks in recent versions of numpy.
self._rotate_btn = np.atleast_1d(rotate_btn).tolist()
self._zoom_btn = np.atleast_1d(zoom_btn).tolist()

def disable_mouse_rotation(self):
"""Disable mouse buttons for 3D rotation and zooming."""
self.mouse_init(rotate_btn=[], zoom_btn=[])

def can_zoom(self):
"""
Return *True* if this axes supports the zoom box button functionality.
Expand Down Expand Up @@ -1069,13 +1069,6 @@ def cla(self):

self.grid(rcParams['axes3d.grid'])

def disable_mouse_rotation(self):
"""Disable mouse button callbacks."""
# Disconnect the various events we set.
for cid in self._cids:
self.figure.canvas.mpl_disconnect(cid)
self._cids = []

def _button_press(self, event):
if event.inaxes == self:
self.button_pressed = event.button
Expand Down