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

Skip to content

Commit e3e7792

Browse files
authored
Merge pull request #16277 from anntzer/mousebuttondocs
Prefer using MouseButton to numeric values in docs and defaults.
2 parents 31ba9ff + 786892b commit e3e7792

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

lib/matplotlib/blocking_input.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from numbers import Integral
2525

2626
from matplotlib import cbook
27+
from matplotlib.backend_bases import MouseButton
2728
import matplotlib.lines as mlines
2829

2930
_log = logging.getLogger(__name__)
@@ -103,15 +104,18 @@ class BlockingMouseInput(BlockingInput):
103104
Callable for retrieving mouse clicks in a blocking way.
104105
105106
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.
107+
delete and backspace are a right click, enter is like a middle click,
108+
and all others are like a left click.
108109
"""
109110

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

114-
def __init__(self, fig, mouse_add=1, mouse_pop=3, mouse_stop=2):
115+
def __init__(self, fig,
116+
mouse_add=MouseButton.LEFT,
117+
mouse_pop=MouseButton.RIGHT,
118+
mouse_stop=MouseButton.MIDDLE):
115119
BlockingInput.__init__(self, fig=fig,
116120
eventslist=('button_press_event',
117121
'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/pyplot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from matplotlib import cbook
3737
from matplotlib.cbook import dedent, deprecated, silent_list, warn_deprecated
3838
from matplotlib import docstring
39-
from matplotlib.backend_bases import FigureCanvasBase
39+
from matplotlib.backend_bases import FigureCanvasBase, MouseButton
4040
from matplotlib.figure import Figure, figaspect
4141
from matplotlib.gridspec import GridSpec
4242
from matplotlib import rcParams, rcParamsDefault, get_backend, rcParamsOrig
@@ -2132,8 +2132,9 @@ def gci():
21322132
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
21332133
@docstring.copy(Figure.ginput)
21342134
def ginput(
2135-
n=1, timeout=30, show_clicks=True, mouse_add=1, mouse_pop=3,
2136-
mouse_stop=2):
2135+
n=1, timeout=30, show_clicks=True,
2136+
mouse_add=MouseButton.LEFT, mouse_pop=MouseButton.RIGHT,
2137+
mouse_stop=MouseButton.MIDDLE):
21372138
return gcf().ginput(
21382139
n=n, timeout=timeout, show_clicks=show_clicks,
21392140
mouse_add=mouse_add, mouse_pop=mouse_pop,

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

tools/boilerplate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# runtime with the proper signatures, a static pyplot.py is simpler for static
1414
# analysis tools to parse.
1515

16+
from enum import Enum
1617
import inspect
1718
from inspect import Parameter
1819
from pathlib import Path
@@ -84,6 +85,9 @@ def __init__(self, value):
8485
self._repr = "np.mean"
8586
elif value is cbook.deprecation._deprecated_parameter:
8687
self._repr = "cbook.deprecation._deprecated_parameter"
88+
elif isinstance(value, Enum):
89+
# Enum str is Class.Name whereas their repr is <Class.Name: value>.
90+
self._repr = str(value)
8791
else:
8892
self._repr = repr(value)
8993

0 commit comments

Comments
 (0)