Revision: 4727
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4727&view=rev
Author:   mdboom
Date:     2007-12-13 10:21:25 -0800 (Thu, 13 Dec 2007)

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

........
  r4718 | mdboom | 2007-12-13 08:40:40 -0500 (Thu, 13 Dec 2007) | 2 lines
  
  Updated to numpy names.
........
  r4720 | jdh2358 | 2007-12-13 11:06:59 -0500 (Thu, 13 Dec 2007) | 2 lines
  
  moved optional rec2* packages out of mlab and into toolkits
........
  r4722 | jdh2358 | 2007-12-13 13:12:11 -0500 (Thu, 13 Dec 2007) | 2 lines
  
  added gtktools and exceltools to toolkits
........

Modified Paths:
--------------
    branches/transforms/API_CHANGES
    branches/transforms/CODING_GUIDE
    branches/transforms/examples/figimage_demo.py
    branches/transforms/examples/logo.py
    branches/transforms/examples/mri_demo.py
    branches/transforms/lib/matplotlib/image.py
    branches/transforms/lib/matplotlib/mlab.py
    branches/transforms/src/_backend_agg.cpp
    branches/transforms/src/_image.cpp

Added Paths:
-----------
    branches/transforms/lib/matplotlib/toolkits/exceltools.py
    branches/transforms/lib/matplotlib/toolkits/gtktools.py

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


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

Modified: branches/transforms/API_CHANGES
===================================================================
--- branches/transforms/API_CHANGES     2007-12-13 18:17:33 UTC (rev 4726)
+++ branches/transforms/API_CHANGES     2007-12-13 18:21:25 UTC (rev 4727)
@@ -169,6 +169,10 @@
 
 END OF TRANSFORMS REFACTORING
 
+    Moved rec2gtk to matplotlib.toolkits.gtktools
+
+    Moved rec2excel to matplotlib.toolkits.exceltools
+
     Removed, dead/experimental ExampleInfo, Namespace and Importer
     code from matplotlib/__init__.py
 0.91.1 Released

Modified: branches/transforms/CODING_GUIDE
===================================================================
--- branches/transforms/CODING_GUIDE    2007-12-13 18:17:33 UTC (rev 4726)
+++ branches/transforms/CODING_GUIDE    2007-12-13 18:21:25 UTC (rev 4727)
@@ -113,6 +113,16 @@
 .emacs will cause emacs to strip trailing white space on save for
 python, C and C++
 
+
+When importing modules from the matplotlib namespace
+
+  import matplotlib.cbook as cbook   # DO
+  from matplotlib import cbook       #DONT
+
+because the latter is ambiguous whether cbook is a module or a
+function to the new developer.  The former makes it explcit that you
+are importing a module or package.
+
 ; and similarly for c++-mode-hook and c-mode-hook
 (add-hook 'python-mode-hook
           (lambda ()

Modified: branches/transforms/examples/figimage_demo.py
===================================================================
--- branches/transforms/examples/figimage_demo.py       2007-12-13 18:17:33 UTC 
(rev 4726)
+++ branches/transforms/examples/figimage_demo.py       2007-12-13 18:21:25 UTC 
(rev 4727)
@@ -13,7 +13,7 @@
 im1 = figimage(Z, xo=50,  yo=0)
 im2 = figimage(Z, xo=100, yo=100, alpha=.8)
 #gray()  # overrides current and sets default
-#savefig('figimage_demo')
+savefig('figimage_demo')
 
 show()
 

Modified: branches/transforms/examples/logo.py
===================================================================
--- branches/transforms/examples/logo.py        2007-12-13 18:17:33 UTC (rev 
4726)
+++ branches/transforms/examples/logo.py        2007-12-13 18:21:25 UTC (rev 
4727)
@@ -5,7 +5,7 @@
 
 # convert data to mV
 x = 1000*0.1*fromstring(
-    file('data/membrane.dat', 'rb').read(), Float32)
+    file('data/membrane.dat', 'rb').read(), float32)
 # 0.0005 is the sample interval
 t = 0.0005*arange(len(x))
 figure(1, figsize=(7,1), dpi=100)

Modified: branches/transforms/examples/mri_demo.py
===================================================================
--- branches/transforms/examples/mri_demo.py    2007-12-13 18:17:33 UTC (rev 
4726)
+++ branches/transforms/examples/mri_demo.py    2007-12-13 18:21:25 UTC (rev 
4727)
@@ -3,7 +3,7 @@
 
 # data are 256x256 16 bit integers
 dfile = 'data/s1045.ima'
-im = fromstring(file(dfile, 'rb').read(), UInt16).astype(Float)
+im = fromstring(file(dfile, 'rb').read(), uint16).astype(float)
 im.shape = 256, 256
 
 #imshow(im, ColormapJet(256))

Modified: branches/transforms/lib/matplotlib/image.py
===================================================================
--- branches/transforms/lib/matplotlib/image.py 2007-12-13 18:17:33 UTC (rev 
4726)
+++ branches/transforms/lib/matplotlib/image.py 2007-12-13 18:21:25 UTC (rev 
4727)
@@ -23,6 +23,7 @@
 from matplotlib._image import *
 
 class AxesImage(martist.Artist, cm.ScalarMappable):
+    zorder = 1
 
     def __init__(self, ax,
                  cmap = None,
@@ -508,18 +509,21 @@
         self.update_dict['array'] = True
 
 class FigureImage(martist.Artist, cm.ScalarMappable):
+    zorder = 1
     def __init__(self, fig,
                  cmap = None,
                  norm = None,
                  offsetx = 0,
                  offsety = 0,
                  origin=None,
+                 **kwargs
                  ):
 
         """
         cmap is a colors.Colormap instance
         norm is a colors.Normalize instance to map luminance to 0-1
 
+        kwargs are an optional list of Artist keyword args
         """
         martist.Artist.__init__(self)
         cm.ScalarMappable.__init__(self, norm, cmap)
@@ -528,6 +532,7 @@
         self.figure = fig
         self.ox = offsetx
         self.oy = offsety
+        self.update(kwargs)
 
     def contains(self, mouseevent):
         """Test whether the mouse event occured within the image.

Modified: branches/transforms/lib/matplotlib/mlab.py
===================================================================
--- branches/transforms/lib/matplotlib/mlab.py  2007-12-13 18:17:33 UTC (rev 
4726)
+++ branches/transforms/lib/matplotlib/mlab.py  2007-12-13 18:21:25 UTC (rev 
4727)
@@ -48,13 +48,13 @@
 
    * rec2csv          : store record array in CSV file
    * rec2excel        : store record array in excel worksheet - required 
pyExcelerator
-   * rec2gtk          : put record array in GTK treeview - requires gtk
+
    * csv2rec          : import record array from CSV file with type inspection
    * rec_append_field : add a field/array to record array
    * rec_drop_fields  : drop fields from record array
    * rec_join         : join two record arrays on sequence of fields
 
-For the rec viewer clases (rec2csv, rec2excel and rec2gtk), there are
+For the rec viewer clases (rec2csv, rec2excel), there are
 a bunch of Format objects you can pass into the functions that will do
 things like color negative values red, set percent formatting and
 scaling, etc.
@@ -1978,7 +1978,7 @@
     join record arrays r1 and r2 on key; key is a tuple of field
     names.  if r1 and r2 have equal values on all the keys in the key
     tuple, then their fields will be merged into a new record array
-    containing the union of the fields of r1 and r2
+    containing the intersection of the fields of r1 and r2
     """
 
     for name in key:
@@ -2343,373 +2343,5 @@
         writer.writerow([func(val) for func, val in zip(funcs, row)])
     fh.close()
 
-# if pyExcelerator is installed, provide an excel view
-try:
-    import pyExcelerator as excel
-except ImportError:
-    pass
-else:
 
-    def xlformat_factory(format):
-        """
-        copy the format, perform any overrides, and attach an xlstyle instance
-        copied format is returned
-        """
-        format = copy.deepcopy(format)
 
-
-
-        xlstyle = excel.XFStyle()
-        if isinstance(format, FormatFloat):
-            zeros = ''.join(['0']*format.precision)
-            xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, zeros)
-        elif isinstance(format, FormatInt):
-            xlstyle.num_format_str = '#,##;[RED]-#,##'
-        elif isinstance(format, FormatPercent):
-            zeros = ''.join(['0']*format.precision)
-            xlstyle.num_format_str = '0.%s%%;[RED]-0.%s%%'%(zeros, zeros)
-            format.scale = 1.
-        else:
-            xlstyle = None
-
-        format.xlstyle = xlstyle
-
-        return format
-
-    def rec2excel(r, ws, formatd=None, rownum=0, colnum=0):
-        """
-        save record array r to excel pyExcelerator worksheet ws
-        starting at rownum.  if ws is string like, assume it is a
-        filename and save to it
-
-        start writing at rownum, colnum
-
-        formatd is a dictionary mapping dtype name -> FormatXL instances
-
-        The next rownum after writing is returned
-        """
-
-        autosave = False
-        if cbook.is_string_like(ws):
-            filename = ws
-            wb = excel.Workbook()
-            ws = wb.add_sheet('worksheet')
-            autosave = True
-
-
-        if formatd is None:
-            formatd = dict()
-
-        formats = []
-        font = excel.Font()
-        font.bold = True
-
-        stylehdr = excel.XFStyle()
-        stylehdr.font = font
-
-        for i, name in enumerate(r.dtype.names):
-            dt = r.dtype[name]
-            format = formatd.get(name)
-            if format is None:
-                format = defaultformatd.get(dt.type, FormatObj())
-
-            format = xlformat_factory(format)
-            ws.write(rownum, colnum+i, name, stylehdr)
-            formats.append(format)
-
-        rownum+=1
-
-
-        ind = npy.arange(len(r.dtype.names))
-        for row in r:
-            for i in ind:
-                val = row[i]
-                format = formats[i]
-                val = format.toval(val)
-                if format.xlstyle is None:
-                    ws.write(rownum, colnum+i, val)
-                else:
-                    if safe_isnan(val):
-                        ws.write(rownum, colnum+i, 'NaN')
-                    else:
-                        ws.write(rownum, colnum+i, val, format.xlstyle)
-            rownum += 1
-
-        if autosave:
-            wb.save(filename)
-        return rownum
-
-
-
-
-# if gtk is installed, provide a gtk view
-try:
-    import gtk, gobject
-except ImportError:
-    pass
-except RuntimeError:
-    pass
-else:
-
-
-    def gtkformat_factory(format, colnum):
-        """
-        copy the format, perform any overrides, and attach an gtk style attrs
-
-
-        xalign = 0.
-        cell = None
-
-        """
-
-        format = copy.copy(format)
-        format.xalign = 0.
-        format.cell = None
-
-        def negative_red_cell(column, cell, model, thisiter):
-            val = model.get_value(thisiter, colnum)
-            try: val = float(val)
-            except: cell.set_property('foreground', 'black')
-            else:
-                if val<0:
-                    cell.set_property('foreground', 'red')
-                else:
-                    cell.set_property('foreground', 'black')
-
-
-        if isinstance(format, FormatFloat) or isinstance(format, FormatInt):
-            format.cell = negative_red_cell
-            format.xalign = 1.
-        elif isinstance(format, FormatDate):
-            format.xalign = 1.
-        return format
-
-
-
-    class SortedStringsScrolledWindow(gtk.ScrolledWindow):
-        """
-        A simple treeview/liststore assuming all columns are strings.
-        Supports ascending/descending sort by clicking on column header
-        """
-
-        def __init__(self, colheaders, formatterd=None):
-            """
-            xalignd if not None, is a dict mapping col header to xalignent 
(default 1)
-
-            formatterd if not None, is a dict mapping col header to a 
ColumnFormatter
-            """
-
-
-            gtk.ScrolledWindow.__init__(self)
-            self.colheaders = colheaders
-            self.seq = None # not initialized with accts
-            self.set_shadow_type(gtk.SHADOW_ETCHED_IN)
-            self.set_policy(gtk.POLICY_AUTOMATIC,
-                            gtk.POLICY_AUTOMATIC)
-
-            types = [gobject.TYPE_STRING] * len(colheaders)
-            model = self.model = gtk.ListStore(*types)
-
-
-            treeview = gtk.TreeView(self.model)
-            treeview.show()
-            treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
-            treeview.set_rules_hint(True)
-
-
-            class Clicked:
-                def __init__(self, parent, i):
-                    self.parent = parent
-                    self.i = i
-                    self.num = 0
-
-                def __call__(self, column):
-                    ind = []
-                    dsu = []
-                    for rownum, thisiter in enumerate(self.parent.iters):
-                        val = model.get_value(thisiter, self.i)
-                        try: val = float(val.strip().rstrip('%'))
-                        except ValueError: pass
-                        if npy.isnan(val): val = npy.inf # force nan to sort 
uniquely
-                        dsu.append((val, rownum))
-                    dsu.sort()
-                    if not self.num%2: dsu.reverse()
-
-                    vals, otherind = zip(*dsu)
-                    ind.extend(otherind)
-
-                    self.parent.model.reorder(ind)
-                    newiters = []
-                    for i in ind:
-                        newiters.append(self.parent.iters[i])
-                    self.parent.iters = newiters[:]
-                    for i, thisiter in enumerate(self.parent.iters):
-                        key = tuple([self.parent.model.get_value(thisiter, j) 
for j in range(len(colheaders))])
-                        self.parent.rownumd[i] = key
-
-                    self.num+=1
-
-
-            if formatterd is None:
-                formatterd = dict()
-
-            formatterd = formatterd.copy()
-
-            for i, header in enumerate(colheaders):
-                renderer = gtk.CellRendererText()
-                if header not in formatterd:
-                    formatterd[header] = ColumnFormatter()
-                formatter = formatterd[header]
-
-                column = gtk.TreeViewColumn(header, renderer, text=i)
-                renderer.set_property('xalign', formatter.xalign)
-                column.connect('clicked', Clicked(self, i))
-                column.set_property('clickable', True)
-
-                if formatter.cell is not None:
-                    column.set_cell_data_func(renderer, formatter.cell)
-
-                treeview.append_column(column)
-
-
-
-            self.formatterd = formatterd
-            self.lastcol = column
-            self.add(treeview)
-            self.treeview = treeview
-            self.clear()
-
-        def clear(self):
-            self.iterd = dict()
-            self.iters = []        # an ordered list of iters
-            self.rownumd = dict()  # a map from rownum -> symbol
-            self.model.clear()
-            self.datad = dict()
-
-
-        def flat(self, row):
-            seq = []
-            for i,val in enumerate(row):
-                formatter = self.formatterd.get(self.colheaders[i])
-                seq.extend([i,formatter.tostr(val)])
-            return seq
-
-        def __delete_selected(self, *unused): # untested
-
-
-            keyd = dict([(thisiter, key) for key, thisiter in 
self.iterd.values()])
-            for row in self.get_selected():
-                key = tuple(row)
-                thisiter = self.iterd[key]
-                self.model.remove(thisiter)
-                del self.datad[key]
-                del self.iterd[key]
-                self.iters.remove(thisiter)
-
-            for i, thisiter in enumerate(self.iters):
-                self.rownumd[i] = keyd[thisiter]
-
-
-
-        def delete_row(self, row):
-            key = tuple(row)
-            thisiter = self.iterd[key]
-            self.model.remove(thisiter)
-
-
-            del self.datad[key]
-            del self.iterd[key]
-            self.rownumd[len(self.iters)] = key
-            self.iters.remove(thisiter)
-
-            for rownum, thiskey in self.rownumd.items():
-                if thiskey==key: del self.rownumd[rownum]
-
-        def add_row(self, row):
-            thisiter = self.model.append()
-            self.model.set(thisiter, *self.flat(row))
-            key = tuple(row)
-            self.datad[key] = row
-            self.iterd[key] = thisiter
-            self.rownumd[len(self.iters)] = key
-            self.iters.append(thisiter)
-
-        def update_row(self, rownum, newrow):
-            key = self.rownumd[rownum]
-            thisiter = self.iterd[key]
-            newkey = tuple(newrow)
-
-            self.rownumd[rownum] = newkey
-            del self.datad[key]
-            del self.iterd[key]
-            self.datad[newkey] = newrow
-            self.iterd[newkey] = thisiter
-
-
-            self.model.set(thisiter, *self.flat(newrow))
-
-        def get_row(self, rownum):
-            key = self.rownumd[rownum]
-            return self.datad[key]
-
-        def get_selected(self):
-            selected = []
-            def foreach(model, path, iter, selected):
-                selected.append(model.get_value(iter, 0))
-
-            self.treeview.get_selection().selected_foreach(foreach, selected)
-            return selected
-
-
-
-    def rec2gtk(r, formatd=None, rownum=0, autowin=True):
-        """
-        save record array r to excel pyExcelerator worksheet ws
-        starting at rownum.  if ws is string like, assume it is a
-        filename and save to it
-
-        formatd is a dictionary mapping dtype name -> FormatXL instances
-
-        This function creates a SortedStringsScrolledWindow (derived
-        from gtk.ScrolledWindow) and returns it.  if autowin is True,
-        a gtk.Window is created, attached to the
-        SortedStringsScrolledWindow instance, shown and returned.  If
-        autowin=False, the caller is responsible for adding the
-        SortedStringsScrolledWindow instance to a gtk widget and
-        showing it.
-        """
-
-
-
-        if formatd is None:
-            formatd = dict()
-
-        formats = []
-        for i, name in enumerate(r.dtype.names):
-            dt = r.dtype[name]
-            format = formatd.get(name)
-            if format is None:
-                format = defaultformatd.get(dt.type, FormatObj())
-            #print 'gtk fmt factory', i, name, format, type(format)
-            format = gtkformat_factory(format, i)
-            formatd[name] = format
-
-
-        colheaders = r.dtype.names
-        scroll = SortedStringsScrolledWindow(colheaders, formatd)
-
-        ind = npy.arange(len(r.dtype.names))
-        for row in r:
-            scroll.add_row(row)
-
-
-        if autowin:
-            win = gtk.Window()
-            win.set_default_size(800,600)
-            win.add(scroll)
-            win.show_all()
-            scroll.win = win
-
-        return scroll
-
-

Copied: branches/transforms/lib/matplotlib/toolkits/exceltools.py (from rev 
4722, trunk/matplotlib/lib/matplotlib/toolkits/exceltools.py)
===================================================================
--- branches/transforms/lib/matplotlib/toolkits/exceltools.py                   
        (rev 0)
+++ branches/transforms/lib/matplotlib/toolkits/exceltools.py   2007-12-13 
18:21:25 UTC (rev 4727)
@@ -0,0 +1,120 @@
+"""
+Some io tools for excel -- requires pypyExcelerator
+
+Example usage:
+
+    import matplotlib.mlab as mlab
+    import matplotlib.toolkits.exceltools as exceltools
+    
+    r = mlab.csv2rec('somefile.csv', checkrows=0)
+
+    formatd = dict(
+        weight = mlab.FormatFloat(2),
+        change = mlab.FormatPercent(2),
+        cost   = mlab.FormatThousands(2),
+        )
+
+
+    exceltools.rec2excel(r, 'test.xls', formatd=formatd)
+    mlab.rec2csv(r, 'test.csv', formatd=formatd)
+
+"""
+import copy
+import numpy as npy
+import pyExcelerator as excel
+import matplotlib.cbook as cbook
+import matplotlib.mlab as mlab
+
+
+def xlformat_factory(format):
+    """
+    copy the format, perform any overrides, and attach an xlstyle instance
+    copied format is returned
+    """
+    format = copy.deepcopy(format)
+
+
+
+    xlstyle = excel.XFStyle()
+    if isinstance(format, mlab.FormatPercent):
+       zeros = ''.join(['0']*format.precision)
+       xlstyle.num_format_str = '0.%s%%;[RED]-0.%s%%'%(zeros, zeros)
+       format.scale = 1.
+    elif isinstance(format, mlab.FormatFloat):
+        zeros = ''.join(['0']*format.precision)
+        xlstyle.num_format_str = '#,##0.%s;[RED]-#,##0.%s'%(zeros, zeros)
+    elif isinstance(format, mlab.FormatInt):
+        xlstyle.num_format_str = '#,##;[RED]-#,##'
+    else:
+        xlstyle = None
+
+    format.xlstyle = xlstyle
+
+    return format
+
+def rec2excel(r, ws, formatd=None, rownum=0, colnum=0):
+    """
+    save record array r to excel pyExcelerator worksheet ws
+    starting at rownum.  if ws is string like, assume it is a
+    filename and save to it
+
+    start writing at rownum, colnum
+
+    formatd is a dictionary mapping dtype name -> mlab.Format instances
+
+    The next rownum after writing is returned
+    """
+
+    autosave = False
+    if cbook.is_string_like(ws):
+        filename = ws
+        wb = excel.Workbook()
+        ws = wb.add_sheet('worksheet')
+        autosave = True
+
+
+    if formatd is None:
+        formatd = dict()
+
+    formats = []
+    font = excel.Font()
+    font.bold = True
+
+    stylehdr = excel.XFStyle()
+    stylehdr.font = font
+
+    for i, name in enumerate(r.dtype.names):
+        dt = r.dtype[name]
+        format = formatd.get(name)
+        if format is None:
+            format = mlab.defaultformatd.get(dt.type, mlab.FormatObj())
+
+        format = xlformat_factory(format)
+        ws.write(rownum, colnum+i, name, stylehdr)
+        formats.append(format)
+
+    rownum+=1
+
+
+    ind = npy.arange(len(r.dtype.names))
+    for row in r:
+        for i in ind:
+            val = row[i]
+            format = formats[i]
+            val = format.toval(val)
+            if format.xlstyle is None:
+                ws.write(rownum, colnum+i, val)
+            else:
+                if mlab.safe_isnan(val):
+                    ws.write(rownum, colnum+i, 'NaN')
+                else:
+                    ws.write(rownum, colnum+i, val, format.xlstyle)
+        rownum += 1
+
+    if autosave:
+        wb.save(filename)
+    return rownum
+
+
+
+

Copied: branches/transforms/lib/matplotlib/toolkits/gtktools.py (from rev 4722, 
trunk/matplotlib/lib/matplotlib/toolkits/gtktools.py)
===================================================================
--- branches/transforms/lib/matplotlib/toolkits/gtktools.py                     
        (rev 0)
+++ branches/transforms/lib/matplotlib/toolkits/gtktools.py     2007-12-13 
18:21:25 UTC (rev 4727)
@@ -0,0 +1,299 @@
+"""
+
+Some gtk specific tools and widgets
+
+   * rec2gtk          : put record array in GTK treeview - requires gtk
+
+Example usage
+
+    import matplotlib.mlab as mlab
+    import matplotlib.toolkits.gtktools as gtktools
+    
+    r = mlab.csv2rec('somefile.csv', checkrows=0)
+
+    formatd = dict(
+        weight = mlab.FormatFloat(2),
+        change = mlab.FormatPercent(2),
+        cost   = mlab.FormatThousands(2),
+        )
+
+
+    exceltools.rec2excel(r, 'test.xls', formatd=formatd)
+    mlab.rec2csv(r, 'test.csv', formatd=formatd)
+
+
+    import gtk
+    scroll = gtktools.rec2gtk(r, formatd=formatd)
+    win = gtk.Window()
+    win.set_size_request(600,800)
+    win.add(scroll)
+    win.show_all()
+    gtk.main()
+
+"""
+import copy
+import gtk, gobject
+import numpy as npy
+import matplotlib.cbook as cbook
+import matplotlib.mlab as mlab
+
+def gtkformat_factory(format, colnum):
+    """
+    copy the format, perform any overrides, and attach an gtk style attrs
+
+
+    xalign = 0.
+    cell = None
+
+    """
+
+    format = copy.copy(format)
+    format.xalign = 0.
+    format.cell = None
+
+    def negative_red_cell(column, cell, model, thisiter):
+        val = model.get_value(thisiter, colnum)
+        try: val = float(val)
+        except: cell.set_property('foreground', 'black')
+        else:
+            if val<0:
+                cell.set_property('foreground', 'red')
+            else:
+                cell.set_property('foreground', 'black')
+
+
+    if isinstance(format, mlab.FormatFloat) or isinstance(format, 
mlab.FormatInt):
+        format.cell = negative_red_cell
+        format.xalign = 1.
+    elif isinstance(format, mlab.FormatDate):
+        format.xalign = 1.
+    return format
+
+
+
+class SortedStringsScrolledWindow(gtk.ScrolledWindow):
+    """
+    A simple treeview/liststore assuming all columns are strings.
+    Supports ascending/descending sort by clicking on column header
+    """
+
+    def __init__(self, colheaders, formatterd=None):
+        """
+        xalignd if not None, is a dict mapping col header to xalignent 
(default 1)
+
+        formatterd if not None, is a dict mapping col header to a 
ColumnFormatter
+        """
+
+
+        gtk.ScrolledWindow.__init__(self)
+        self.colheaders = colheaders
+        self.seq = None # not initialized with accts
+        self.set_shadow_type(gtk.SHADOW_ETCHED_IN)
+        self.set_policy(gtk.POLICY_AUTOMATIC,
+                        gtk.POLICY_AUTOMATIC)
+
+        types = [gobject.TYPE_STRING] * len(colheaders)
+        model = self.model = gtk.ListStore(*types)
+
+
+        treeview = gtk.TreeView(self.model)
+        treeview.show()
+        treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
+        treeview.set_rules_hint(True)
+
+
+        class Clicked:
+            def __init__(self, parent, i):
+                self.parent = parent
+                self.i = i
+                self.num = 0
+
+            def __call__(self, column):
+                ind = []
+                dsu = []
+                for rownum, thisiter in enumerate(self.parent.iters):
+                    val = model.get_value(thisiter, self.i)
+                    try: val = float(val.strip().rstrip('%'))
+                    except ValueError: pass
+                    if npy.isnan(val): val = npy.inf # force nan to sort 
uniquely
+                    dsu.append((val, rownum))
+                dsu.sort()
+                if not self.num%2: dsu.reverse()
+
+                vals, otherind = zip(*dsu)
+                ind.extend(otherind)
+
+                self.parent.model.reorder(ind)
+                newiters = []
+                for i in ind:
+                    newiters.append(self.parent.iters[i])
+                self.parent.iters = newiters[:]
+                for i, thisiter in enumerate(self.parent.iters):
+                    key = tuple([self.parent.model.get_value(thisiter, j) for 
j in range(len(colheaders))])
+                    self.parent.rownumd[i] = key
+
+                self.num+=1
+
+
+        if formatterd is None:
+            formatterd = dict()
+
+        formatterd = formatterd.copy()
+
+        for i, header in enumerate(colheaders):
+            renderer = gtk.CellRendererText()
+            if header not in formatterd:
+                formatterd[header] = ColumnFormatter()
+            formatter = formatterd[header]
+
+            column = gtk.TreeViewColumn(header, renderer, text=i)
+            renderer.set_property('xalign', formatter.xalign)
+            column.connect('clicked', Clicked(self, i))
+            column.set_property('clickable', True)
+
+            if formatter.cell is not None:
+                column.set_cell_data_func(renderer, formatter.cell)
+
+            treeview.append_column(column)
+
+
+
+        self.formatterd = formatterd
+        self.lastcol = column
+        self.add(treeview)
+        self.treeview = treeview
+        self.clear()
+
+    def clear(self):
+        self.iterd = dict()
+        self.iters = []        # an ordered list of iters
+        self.rownumd = dict()  # a map from rownum -> symbol
+        self.model.clear()
+        self.datad = dict()
+
+
+    def flat(self, row):
+        seq = []
+        for i,val in enumerate(row):
+            formatter = self.formatterd.get(self.colheaders[i])
+            seq.extend([i,formatter.tostr(val)])
+        return seq
+
+    def __delete_selected(self, *unused): # untested
+
+
+        keyd = dict([(thisiter, key) for key, thisiter in self.iterd.values()])
+        for row in self.get_selected():
+            key = tuple(row)
+            thisiter = self.iterd[key]
+            self.model.remove(thisiter)
+            del self.datad[key]
+            del self.iterd[key]
+            self.iters.remove(thisiter)
+
+        for i, thisiter in enumerate(self.iters):
+            self.rownumd[i] = keyd[thisiter]
+
+
+
+    def delete_row(self, row):
+        key = tuple(row)
+        thisiter = self.iterd[key]
+        self.model.remove(thisiter)
+
+
+        del self.datad[key]
+        del self.iterd[key]
+        self.rownumd[len(self.iters)] = key
+        self.iters.remove(thisiter)
+
+        for rownum, thiskey in self.rownumd.items():
+            if thiskey==key: del self.rownumd[rownum]
+
+    def add_row(self, row):
+        thisiter = self.model.append()
+        self.model.set(thisiter, *self.flat(row))
+        key = tuple(row)
+        self.datad[key] = row
+        self.iterd[key] = thisiter
+        self.rownumd[len(self.iters)] = key
+        self.iters.append(thisiter)
+
+    def update_row(self, rownum, newrow):
+        key = self.rownumd[rownum]
+        thisiter = self.iterd[key]
+        newkey = tuple(newrow)
+
+        self.rownumd[rownum] = newkey
+        del self.datad[key]
+        del self.iterd[key]
+        self.datad[newkey] = newrow
+        self.iterd[newkey] = thisiter
+
+
+        self.model.set(thisiter, *self.flat(newrow))
+
+    def get_row(self, rownum):
+        key = self.rownumd[rownum]
+        return self.datad[key]
+
+    def get_selected(self):
+        selected = []
+        def foreach(model, path, iter, selected):
+            selected.append(model.get_value(iter, 0))
+
+        self.treeview.get_selection().selected_foreach(foreach, selected)
+        return selected
+
+
+
+def rec2gtk(r, formatd=None, rownum=0, autowin=True):
+    """
+    save record array r to excel pyExcelerator worksheet ws
+    starting at rownum.  if ws is string like, assume it is a
+    filename and save to it
+
+    formatd is a dictionary mapping dtype name -> mlab.Format instances
+
+    This function creates a SortedStringsScrolledWindow (derived
+    from gtk.ScrolledWindow) and returns it.  if autowin is True,
+    a gtk.Window is created, attached to the
+    SortedStringsScrolledWindow instance, shown and returned.  If
+    autowin=False, the caller is responsible for adding the
+    SortedStringsScrolledWindow instance to a gtk widget and
+    showing it.
+    """
+
+
+
+    if formatd is None:
+        formatd = dict()
+
+    formats = []
+    for i, name in enumerate(r.dtype.names):
+        dt = r.dtype[name]
+        format = formatd.get(name)
+        if format is None:
+            format = mlab.defaultformatd.get(dt.type, mlab.FormatObj())
+        #print 'gtk fmt factory', i, name, format, type(format)
+        format = gtkformat_factory(format, i)
+        formatd[name] = format
+
+
+    colheaders = r.dtype.names
+    scroll = SortedStringsScrolledWindow(colheaders, formatd)
+
+    ind = npy.arange(len(r.dtype.names))
+    for row in r:
+        scroll.add_row(row)
+
+
+    if autowin:
+        win = gtk.Window()
+        win.set_default_size(800,600)
+        win.add(scroll)
+        win.show_all()
+        scroll.win = win
+
+    return scroll
+

Modified: branches/transforms/src/_backend_agg.cpp
===================================================================
--- branches/transforms/src/_backend_agg.cpp    2007-12-13 18:17:33 UTC (rev 
4726)
+++ branches/transforms/src/_backend_agg.cpp    2007-12-13 18:21:25 UTC (rev 
4727)
@@ -253,7 +253,7 @@
   alphaMaskRenderingBuffer = new agg::rendering_buffer;
   alphaMaskRenderingBuffer->attach(alphaBuffer, width, height, stride);
   alphaMask               = new alpha_mask_type(*alphaMaskRenderingBuffer);
-  //jdh
+
   pixfmtAlphaMask         = new agg::pixfmt_gray8(*alphaMaskRenderingBuffer);
   rendererBaseAlphaMask           = new 
renderer_base_alpha_mask_type(*pixfmtAlphaMask);
   rendererAlphaMask       = new 
renderer_alpha_mask_type(*rendererBaseAlphaMask);

Modified: branches/transforms/src/_image.cpp
===================================================================
--- branches/transforms/src/_image.cpp  2007-12-13 18:17:33 UTC (rev 4726)
+++ branches/transforms/src/_image.cpp  2007-12-13 18:21:25 UTC (rev 4727)
@@ -299,7 +299,7 @@
 
 Py::Object
 Image::get_matrix(const Py::Tuple& args) {
-  _VERBOSE("Image::get_size");
+  _VERBOSE("Image::get_matrix");
 
   args.verify_length(0);
 
@@ -520,7 +520,7 @@
 
 Py::Object
 Image::get_size_out(const Py::Tuple& args) {
-  _VERBOSE("Image::get_size");
+  _VERBOSE("Image::get_size_out");
 
   args.verify_length(0);
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to