Skip to content

Commit 2a9a215

Browse files
committed
add Ben Axelrod's button patch for RectangleSelector
svn path=/trunk/matplotlib/; revision=8150
1 parent 5f8a88a commit 2a9a215

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

examples/widgets/rectangle_selector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ def line_select_callback(event1, event2):
3030
# drawtype is 'box' or 'line' or 'none'
3131
LS = RectangleSelector(current_ax, line_select_callback,
3232
drawtype='box',useblit=True,
33+
button = [1, 3], # don't use center mouse button
3334
minspanx=5,minspany=5,spancoords='pixels')
3435
show()

lib/matplotlib/widgets.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,8 @@ def toggle_selector(event):
10171017
"""
10181018
def __init__(self, ax, onselect, drawtype='box',
10191019
minspanx=None, minspany=None, useblit=False,
1020-
lineprops=None, rectprops=None, spancoords='data'):
1020+
lineprops=None, rectprops=None, spancoords='data',
1021+
button=None):
10211022

10221023
"""
10231024
Create a selector in ax. When a selection is made, clear
@@ -1047,6 +1048,15 @@ def __init__(self, ax, onselect, drawtype='box',
10471048
spancoords is one of 'data' or 'pixels'. If 'data', minspanx
10481049
and minspanx will be interpreted in the same coordinates as
10491050
the x and ya axis, if 'pixels', they are in pixels
1051+
1052+
button is a list of integers indicating which mouse buttons should
1053+
be used for rectangle selection. You can also specify a single
1054+
integer if only a single button is desired. Default is None, which
1055+
does not limit which button can be used.
1056+
Note, typically:
1057+
1 = left mouse button
1058+
2 = center mouse button (scroll wheel)
1059+
3 = right mouse button
10501060
"""
10511061
self.ax = ax
10521062
self.visible = True
@@ -1084,6 +1094,11 @@ def __init__(self, ax, onselect, drawtype='box',
10841094
self.minspanx = minspanx
10851095
self.minspany = minspany
10861096

1097+
if button is None or isinstance(button, list):
1098+
self.validButtons = button
1099+
elif isinstance(button, int):
1100+
self.validButtons = [button]
1101+
10871102
assert(spancoords in ('data', 'pixels'))
10881103

10891104
self.spancoords = spancoords
@@ -1109,6 +1124,12 @@ def ignore(self, event):
11091124
if not self.canvas.widgetlock.available(self):
11101125
return True
11111126

1127+
# Only do rectangle selection if event was triggered
1128+
# with a desired button
1129+
if self.validButtons is not None:
1130+
if not event.button in self.validButtons:
1131+
return True
1132+
11121133
# If no button was pressed yet ignore the event if it was out
11131134
# of the axes
11141135
if self.eventpress == None:

0 commit comments

Comments
 (0)