Here is a patch for a new feature for the rectangle selector. it allows the
user to specify which mouse button or buttons to use for the rectangle
selection. Also included in the diff is a one line change to the
rectangle_selector example code to demonstrate the use of the feature.
Thanks,
-Ben
Index: lib/matplotlib/widgets.py
===================================================================
--- lib/matplotlib/widgets.py (revision 8149)
+++ lib/matplotlib/widgets.py (working copy)
@@ -1017,7 +1017,8 @@
"""
def __init__(self, ax, onselect, drawtype='box',
minspanx=None, minspany=None, useblit=False,
- lineprops=None, rectprops=None, spancoords='data'):
+ lineprops=None, rectprops=None, spancoords='data',
+ useBtn=None):
"""
Create a selector in ax. When a selection is made, clear
@@ -1047,6 +1048,15 @@
spancoords is one of 'data' or 'pixels'. If 'data', minspanx
and minspanx will be interpreted in the same coordinates as
the x and ya axis, if 'pixels', they are in pixels
+
+ useBtn is a list of integers indicating which mouse buttons should
+ be used for rectangle selection. You can also specify a single
+ integer if only a single button is desired. Default is None, which
+ does not limit which button can be used.
+ Note, typically:
+ 1 = left mouse button
+ 2 = center mouse button (scroll wheel)
+ 3 = right mouse button
"""
self.ax = ax
self.visible = True
@@ -1084,6 +1094,11 @@
self.minspanx = minspanx
self.minspany = minspany
+ if useBtn is None or isinstance(useBtn, list):
+ self.validButtons = useBtn
+ elif isinstance(useBtn, int):
+ self.validButtons = [useBtn]
+
assert(spancoords in ('data', 'pixels'))
self.spancoords = spancoords
@@ -1109,6 +1124,12 @@
if not self.canvas.widgetlock.available(self):
return True
+ # Only do rectangle selection if event was triggered
+ # with a desired button
+ if self.validButtons is not None:
+ if not event.button in self.validButtons:
+ return True
+
# If no button was pressed yet ignore the event if it was out
# of the axes
if self.eventpress == None:
Index: examples/widgets/rectangle_selector.py
===================================================================
--- examples/widgets/rectangle_selector.py (revision 8149)
+++ examples/widgets/rectangle_selector.py (working copy)
@@ -30,5 +30,6 @@
# drawtype is 'box' or 'line' or 'none'
LS = RectangleSelector(current_ax, line_select_callback,
drawtype='box',useblit=True,
+ useBtn = [1, 3], # don't use center mouse button
minspanx=5,minspany=5,spancoords='pixels')
show()
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel