Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ecde103

Browse files
committed
Reword docstring of panning callbacks, and pass them a MouseButton.
... rather than a plain int -- this makes the documentation easier, and MouseButton inherits from int anyways.
1 parent e41277c commit ecde103

File tree

2 files changed

+28
-41
lines changed

2 files changed

+28
-41
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4190,17 +4190,16 @@ def start_pan(self, x, y, button):
41904190
"""
41914191
Called when a pan operation has started.
41924192
4193-
*x*, *y* are the mouse coordinates in display coords.
4194-
button is the mouse button number:
4195-
4196-
* 1: LEFT
4197-
* 2: MIDDLE
4198-
* 3: RIGHT
4199-
4200-
.. note::
4201-
4202-
Intended to be overridden by new projection types.
4193+
Parameters
4194+
----------
4195+
x, y : float
4196+
The mouse coordinates in display coords.
4197+
button : `.MouseButton`
4198+
The pressed mouse button.
42034199
4200+
Notes
4201+
-----
4202+
This is intended to be overridden by new projection types.
42044203
"""
42054204
self._pan_start = types.SimpleNamespace(
42064205
lim=self.viewLim.frozen(),
@@ -4212,34 +4211,30 @@ def start_pan(self, x, y, button):
42124211

42134212
def end_pan(self):
42144213
"""
4215-
Called when a pan operation completes (when the mouse button
4216-
is up.)
4217-
4218-
.. note::
4219-
4220-
Intended to be overridden by new projection types.
4214+
Called when a pan operation completes (when the mouse button is up.)
42214215
4216+
Notes
4217+
-----
4218+
This is intended to be overridden by new projection types.
42224219
"""
42234220
del self._pan_start
42244221

42254222
def drag_pan(self, button, key, x, y):
42264223
"""
42274224
Called when the mouse moves during a pan operation.
42284225
4229-
*button* is the mouse button number:
4230-
4231-
* 1: LEFT
4232-
* 2: MIDDLE
4233-
* 3: RIGHT
4234-
4235-
*key* is a "shift" key
4236-
4237-
*x*, *y* are the mouse coordinates in display coords.
4238-
4239-
.. note::
4240-
4241-
Intended to be overridden by new projection types.
4226+
Parameters
4227+
----------
4228+
button : `.MouseButton`
4229+
The pressed mouse button.
4230+
key : str or None
4231+
The pressed key, if any.
4232+
x, y : float
4233+
The mouse coordinates in display coords.
42424234
4235+
Notes
4236+
-----
4237+
This is intended to be overridden by new projection types.
42434238
"""
42444239
def format_deltas(key, dx, dy):
42454240
if key == 'control':

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,19 +2877,14 @@ def press(self, event):
28772877

28782878
def press_pan(self, event):
28792879
"""Callback for mouse button press in pan/zoom mode."""
2880-
2881-
if event.button == 1:
2882-
self._button_pressed = 1
2883-
elif event.button == 3:
2884-
self._button_pressed = 3
2880+
if event.button in [1, 3]:
2881+
self._button_pressed = event.button
28852882
else:
28862883
self._button_pressed = None
28872884
return
2888-
28892885
if self._nav_stack() is None:
28902886
# set the home button to this view
28912887
self.push_current()
2892-
28932888
x, y = event.x, event.y
28942889
self._xypress = []
28952890
for i, a in enumerate(self.canvas.figure.get_axes()):
@@ -2900,7 +2895,6 @@ def press_pan(self, event):
29002895
self.canvas.mpl_disconnect(self._idDrag)
29012896
self._idDrag = self.canvas.mpl_connect('motion_notify_event',
29022897
self.drag_pan)
2903-
29042898
self.press(event)
29052899

29062900
def press_zoom(self, event):
@@ -2917,10 +2911,8 @@ def press_zoom(self, event):
29172911
self._ids_zoom = []
29182912
return
29192913

2920-
if event.button == 1:
2921-
self._button_pressed = 1
2922-
elif event.button == 3:
2923-
self._button_pressed = 3
2914+
if event.button in [1, 3]:
2915+
self._button_pressed = event.button
29242916
else:
29252917
self._button_pressed = None
29262918
return

0 commit comments

Comments
 (0)