|
From: <jd...@us...> - 2010-02-23 17:02:19
|
Revision: 8150
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8150&view=rev
Author: jdh2358
Date: 2010-02-23 17:02:11 +0000 (Tue, 23 Feb 2010)
Log Message:
-----------
add Ben Axelrod's button patch for RectangleSelector
Modified Paths:
--------------
trunk/matplotlib/examples/widgets/rectangle_selector.py
trunk/matplotlib/lib/matplotlib/widgets.py
Modified: trunk/matplotlib/examples/widgets/rectangle_selector.py
===================================================================
--- trunk/matplotlib/examples/widgets/rectangle_selector.py 2010-02-22 23:23:05 UTC (rev 8149)
+++ trunk/matplotlib/examples/widgets/rectangle_selector.py 2010-02-23 17:02:11 UTC (rev 8150)
@@ -30,5 +30,6 @@
# drawtype is 'box' or 'line' or 'none'
LS = RectangleSelector(current_ax, line_select_callback,
drawtype='box',useblit=True,
+ button = [1, 3], # don't use center mouse button
minspanx=5,minspany=5,spancoords='pixels')
show()
Modified: trunk/matplotlib/lib/matplotlib/widgets.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/widgets.py 2010-02-22 23:23:05 UTC (rev 8149)
+++ trunk/matplotlib/lib/matplotlib/widgets.py 2010-02-23 17:02:11 UTC (rev 8150)
@@ -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',
+ button=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
+
+ button 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 button is None or isinstance(button, list):
+ self.validButtons = button
+ elif isinstance(button, int):
+ self.validButtons = [button]
+
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:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|