Revision: 3870
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3870&view=rev
Author:   mdboom
Date:     2007-09-20 11:02:51 -0700 (Thu, 20 Sep 2007)

Log Message:
-----------
Merged revisions 3866-3869 via svnmerge from 
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib

........
  r3867 | jdh2358 | 2007-09-20 10:13:51 -0400 (Thu, 20 Sep 2007) | 1 line
  
  committed rectangle selector lock patch
........

Modified Paths:
--------------
    branches/transforms/lib/matplotlib/mlab.py
    branches/transforms/lib/matplotlib/widgets.py

Property Changed:
----------------
    branches/transforms/


Property changes on: branches/transforms
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk/matplotlib:1-3865
   + /trunk/matplotlib:1-3869

Modified: branches/transforms/lib/matplotlib/mlab.py
===================================================================
--- branches/transforms/lib/matplotlib/mlab.py  2007-09-20 18:00:32 UTC (rev 
3869)
+++ branches/transforms/lib/matplotlib/mlab.py  2007-09-20 18:02:51 UTC (rev 
3870)
@@ -1255,7 +1255,7 @@
     if unpack: return X.transpose()
     else: return X
 
-def csv2rec(fname, comments='#', skiprows=1, checkrows=5, delimiter=',',
+def csv2rec(fname, comments='#', skiprows=0, checkrows=5, delimiter=',',
             converterd=None, names=None, missing=None):
     """
     Load data from comma/space/tab delimited file in fname into a
@@ -1314,6 +1314,14 @@
             else: return get_func(item, funcmap[func])    # recurse
         else: return func
 
+
+    # map column names that clash with builtins -- TODO - extend this list
+    itemd = {
+        'return' : 'return_',
+        'file' : 'file_',
+        'print' : 'print_',
+        }
+        
     def get_converters(reader):
 
         converters = None
@@ -1352,6 +1360,7 @@
             if not len(item):
                 item = 'column%d'%i
 
+            item = itemd.get(item, item)
             cnt = seen.get(item, 0)
             if cnt>0:
                 names.append(item + '%d'%cnt)

Modified: branches/transforms/lib/matplotlib/widgets.py
===================================================================
--- branches/transforms/lib/matplotlib/widgets.py       2007-09-20 18:00:32 UTC 
(rev 3869)
+++ branches/transforms/lib/matplotlib/widgets.py       2007-09-20 18:02:51 UTC 
(rev 3870)
@@ -955,24 +955,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,
@@ -1001,8 +1017,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
@@ -1012,6 +1026,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
 
@@ -1052,6 +1067,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:
@@ -1142,6 +1165,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 was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to