@@ -1319,6 +1319,11 @@ def on_key_press(self, event):
13191319 """Key press event handler and validator"""
13201320 if self .active :
13211321 key = event .key or ''
1322+ if key == 'escape' :
1323+ for artist in self .artists :
1324+ artist .set_visible (False )
1325+ self .update ()
1326+ return
13221327 if 'shift' in key :
13231328 self .state .add ('square' )
13241329 if 'ctrl' in key or 'control' in key :
@@ -1656,7 +1661,8 @@ def toggle_selector(event):
16561661 def __init__ (self , ax , onselect , drawtype = 'patch' ,
16571662 minspanx = None , minspany = None , useblit = False ,
16581663 lineprops = None , rectprops = None , spancoords = 'data' ,
1659- button = None , maxdist = 10 , marker_props = None ):
1664+ button = None , maxdist = 10 , marker_props = None ,
1665+ interactive = False ):
16601666
16611667 """
16621668 Create a selector in *ax*. When a selection is made, clear
@@ -1683,7 +1689,7 @@ def __init__(self, ax, onselect, drawtype='patch',
16831689 Use *drawtype* if you want the mouse to draw a line,
16841690 a box or nothing between click and actual position by setting
16851691
1686- ``drawtype = 'line'``, ``drawtype='box '`` or ``drawtype = 'none'``.
1692+ ``drawtype = 'line'``, ``drawtype='patch '`` or ``drawtype = 'none'``.
16871693
16881694 *spancoords* is one of 'data' or 'pixels'. If 'data', *minspanx*
16891695 and *minspanx* will be interpreted in the same coordinates as
@@ -1698,12 +1704,16 @@ def __init__(self, ax, onselect, drawtype='patch',
16981704 1 = left mouse button
16991705 2 = center mouse button (scroll wheel)
17001706 3 = right mouse button
1707+
1708+ *interactive* will draw a set of handles and allow you interact
1709+ with the widget after it is drawn.
17011710 """
17021711 _SelectorWidget .__init__ (self , ax , onselect , useblit = useblit ,
1703- button = button )
1712+ button = button )
17041713
17051714 self .to_draw = None
17061715 self .visible = True
1716+ self .interactive = interactive
17071717
17081718 if drawtype == 'box' : # backwards compatibility
17091719 drawtype = 'patch'
@@ -1765,21 +1775,28 @@ def __init__(self, ax, onselect, drawtype='patch',
17651775 self ._corner_handles .artist ,
17661776 self ._edge_handles .artist ]
17671777
1778+ if not self .interactive :
1779+ self .artists = [self .to_draw ]
1780+
17681781 def _press (self , event ):
17691782 """on button press event"""
17701783 # make the drawed box/line visible get the click-coordinates,
17711784 # button, ...
1772- self .set_visible ( self .visible )
1773- self ._set_active_handle (event )
1785+ if self .interactive and self .to_draw . get_visible ():
1786+ self ._set_active_handle (event )
17741787
1775- if self .active_handle is None :
1788+ self .set_visible (self .visible )
1789+ if self .active_handle is None or not self .interactive :
17761790 # Clear previous rectangle before drawing new rectangle.
17771791 self .update ()
17781792
17791793 self .set_visible (self .visible )
17801794
17811795 def _release (self , event ):
17821796 """on button release event"""
1797+ if not self .interactive :
1798+ self .to_draw .set_visible (False )
1799+
17831800 if self .spancoords == 'data' :
17841801 xmin , ymin = self .eventpress .xdata , self .eventpress .ydata
17851802 xmax , ymax = self .eventrelease .xdata , self .eventrelease .ydata
0 commit comments