Hello John,

thank you for your reply.
I'm not sure I really understood the widgetlock, but I think the following 
lines seem to do what I want - (Am I right?):

+        # If canvas was locked
+        if not self.canvas.widgetlock.available(self):
+            return True

I attached once more my patch including these new lines.

best regards,
Matthias

On Tuesday 26 June 2007 16:35, John Hunter wrote:
> On 6/26/07, Matthias Michler <[EMAIL PROTECTED]> wrote:
> > Hello everybody,
> >
> > first of all: Sorry for posting to my own thread.
> > But I really like this new feature and may be the last message got lost
> > among the lots of mpl-mails. So I ask you once more for comments on this
> > issue (please).
> >
> > Is this new feature a bug to some of the RectangleSelector-users or a
> > real feature?
> > Could it be part of mpl?
>
> Thanks for reminding us on this one.  Making these widgets work well
> together can be a pain.  I wrote some locking functionality to help
> coordinate them, is any of this functionality useful to you?
>
> The patch looks mostly correct, but the code trying to get the toolbar
> state is problematic
>
> +        # If zoom mode was activated
> +        if not (Gcf.get_active().toolbar.mode == ''):
> +            return True
> +
>
> Gcf is a pylab construct, and code in widgets must not be dependent on
> pylab.  Also, using the mode string here looks a bit hackish since it
> is designed to communicate to the user rather than represent state.
> See if you can use the lock functionality to achieve the same purpose
> -- eg look at how widgetlock is used in the toolbar in backend_bases.
> If this is not viable, let me know why and we'll figure a better way
> for these widgets to communicate.
>
> JDH
Index: widgets.py
===================================================================
--- widgets.py	(revision 3414)
+++ widgets.py	(working copy)
@@ -954,24 +954,40 @@
         warnings.warn('Use SpanSelector instead!', DeprecationWarning)
         SpanSelector.__init__(self, ax, onselect, 'horizontal', **kwargs)
 
+
 class RectangleSelector:
     """
     Select a min/max range of the x axes for a matplotlib Axes
 
     Example usage:
 
-      ax = subplot(111)
-      ax.plot(x,y)
+        from matplotlib.widgets import  RectangleSelector
+        from pylab import *
 
-      def onselect(eclick, erelease):
+        def onselect(eclick, erelease):
           'eclick and erelease are matplotlib events at press and release'
-          print 'startposition : (%f,%f)'%(eclick.xdata, eclick.ydata)
-          print 'endposition   : (%f,%f)'%(erelease.xdata, erelease.ydata)
-          print 'used button   : ', eclick.button
+          print ' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)
+          print ' endposition   : (%f, %f)' % (erelease.xdata, erelease.ydata)
+          print ' used button   : ', eclick.button
 
-      span = Selector(ax, onselect,drawtype='box')
-      show()
+        def toggle_Selector(event):
+            print ' Key pressed.'
+            if event.key in ['Q', 'q'] and toggle_Selector.RS.active:
+                print ' RectangleSelector deactivated.'
+                toggle_Selector.RS.set_active(False)
+            if event.key in ['A', 'a'] and not toggle_Selector.RS.active:
+                print ' RectangleSelector activated.'
+                toggle_Selector.RS.set_active(True)
 
+        x = arange(100)/(99.0)
+        y = sin(x)
+        fig = figure
+        ax = subplot(111)
+        ax.plot(x,y)
+
+        toggle_Selector.RS = RectangleSelector(ax, onselect, drawtype='line')
+        connect('key_press_event', toggle_Selector)
+        show()
     """
     def __init__(self, ax, onselect, drawtype='box',
                  minspanx=None, minspany=None, useblit=False,
@@ -1000,8 +1016,6 @@
         Use type if you want the mouse to draw a line, a box or nothing
         between click and actual position ny setting
         drawtype = 'line', drawtype='box' or drawtype = 'none'.
-
-
         """
         self.ax = ax
         self.visible = True
@@ -1011,6 +1025,7 @@
         self.canvas.mpl_connect('button_release_event', self.release)
         self.canvas.mpl_connect('draw_event', self.update_background)
 
+        self.active = True                    # for activation / deactivation
         self.to_draw = None
         self.background = None
 
@@ -1051,6 +1066,14 @@
 
     def ignore(self, event):
         'return True if event should be ignored'
+        # If RectangleSelector is not active :
+        if not self.active:
+            return True
+        
+        # If canvas was locked
+        if not self.canvas.widgetlock.available(self):
+            return True
+        
         # If no button was pressed yet ignore the event if it was out
         # of the axes
         if self.eventpress == None:
@@ -1141,6 +1164,17 @@
             self.update()
             return False
 
+    def set_active(self, active):
+        """ Use this to activate / deactivate the RectangleSelector
+
+            from your program with an boolean variable 'active'.
+        """
+        self.active = active
+
+    def get_active(self):
+        """ to get status of active mode (boolean variable)"""
+        return self.active 
+
 class Lasso(Widget):
     def __init__(self, ax, xy, callback=None, useblit=True):
         self.axes = ax
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to