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

Skip to content

Commit 9d6542c

Browse files
committed
Prefer using MouseButton to numeric values in docs and defaults.
They are more self-explanatory (and completely backcompatible, as they inherit from int).
1 parent cc55b47 commit 9d6542c

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

lib/matplotlib/blocking_input.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ class BlockingMouseInput(BlockingInput):
103103
Callable for retrieving mouse clicks in a blocking way.
104104
105105
This class will also retrieve keypresses and map them to mouse clicks:
106-
delete and backspace are like mouse button 3, enter is like mouse button 2
107-
and all others are like mouse button 1.
106+
delete and backspace are a right click, enter is like a middle click,
107+
and all others are like a left click.
108108
"""
109109

110-
button_add = 1
111-
button_pop = 3
112-
button_stop = 2
110+
button_add = MouseButton.LEFT
111+
button_pop = MouseButton.RIGHT
112+
button_stop = MouseButton.MIDDLE
113113

114-
def __init__(self, fig, mouse_add=1, mouse_pop=3, mouse_stop=2):
114+
def __init__(self, fig,
115+
mouse_add=MouseButton.LEFT,
116+
mouse_pop=MouseButton.RIGHT,
117+
mouse_stop=MouseButton.MIDDLE):
115118
BlockingInput.__init__(self, fig=fig,
116119
eventslist=('button_press_event',
117120
'key_press_event'))

lib/matplotlib/figure.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
import matplotlib.artist as martist
2323
from matplotlib.artist import Artist, allow_rasterization
24-
from matplotlib.backend_bases import FigureCanvasBase, NonGuiException
24+
from matplotlib.backend_bases import (
25+
FigureCanvasBase, NonGuiException, MouseButton)
2526
import matplotlib.cbook as cbook
2627
import matplotlib.colorbar as cbar
2728
import matplotlib.image as mimage
@@ -2233,8 +2234,10 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
22332234
ax.set_position(ax.figbox)
22342235
self.stale = True
22352236

2236-
def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1,
2237-
mouse_pop=3, mouse_stop=2):
2237+
def ginput(self, n=1, timeout=30, show_clicks=True,
2238+
mouse_add=MouseButton.LEFT,
2239+
mouse_pop=MouseButton.RIGHT,
2240+
mouse_stop=MouseButton.MIDDLE):
22382241
"""
22392242
Blocking call to interact with a figure.
22402243
@@ -2248,13 +2251,7 @@ def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1,
22482251
- Stop the interaction and return the points added so far.
22492252
22502253
The actions are assigned to mouse buttons via the arguments
2251-
*mouse_add*, *mouse_pop* and *mouse_stop*. Mouse buttons are defined
2252-
by the numbers:
2253-
2254-
- 1: left mouse button
2255-
- 2: middle mouse button
2256-
- 3: right mouse button
2257-
- None: no mouse button
2254+
*mouse_add*, *mouse_pop* and *mouse_stop*.
22582255
22592256
Parameters
22602257
----------
@@ -2266,11 +2263,11 @@ def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1,
22662263
will never timeout.
22672264
show_clicks : bool, default: True
22682265
If True, show a red cross at the location of each click.
2269-
mouse_add : {1, 2, 3, None}, default: 1 (left click)
2266+
mouse_add : `.MouseButton` or None, default: `.MouseButton.LEFT`
22702267
Mouse button used to add points.
2271-
mouse_pop : {1, 2, 3, None}, default: 3 (right click)
2268+
mouse_pop : `.MouseButton` or None, default: `.MouseButton.RIGHT`
22722269
Mouse button used to remove the most recently added point.
2273-
mouse_stop : {1, 2, 3, None}, default: 2 (middle click)
2270+
mouse_stop : `.MouseButton` or None, default: `.MouseButton.MIDDLE`
22742271
Mouse button used to stop input.
22752272
22762273
Returns

lib/matplotlib/widgets.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,11 +2008,6 @@ def __init__(self, ax, onselect, drawtype='box',
20082008
*button* is the `.MouseButton` or list of `.MouseButton`\s used for
20092009
rectangle selection. Default is *None*, which means any button.
20102010
2011-
Note, typically:
2012-
1 = left mouse button
2013-
2 = center mouse button (scroll wheel)
2014-
3 = right mouse button
2015-
20162011
*interactive* will draw a set of handles and allow you interact
20172012
with the widget after it is drawn.
20182013

0 commit comments

Comments
 (0)