@@ -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