mlab reorganization

I moved the tools in mlab that did optional imports (the rec2gtk and
rec2excel functions and their dependencies) out of mlab into
toolkits.gtktools and toolkits.exceltools. As Michael noted, these
imports can be expensive for users with gtk on their system and do not
belong in mlab. In some cases, eg logged in over a dumb terminal with
no x11 but where gtk is present, they also trigger text warnings or
errors from gtk, so are a nuisance. I thought it was worth cleaning
this up for the bugfix release.

If you get a minute to test before the release, that would help -- the
excel part requires pyExcelerator, which is pure python
http://sourceforge.net/projects/pyexcelerator

import gtk
import matplotlib.mlab as mlab
import matplotlib.toolkits.gtktools as gtktools
import matplotlib.toolkits.exceltools as exceltools

r = mlab.csv2rec('test.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)

scroll = gtktools.rec2gtk(r, formatd=formatd, autowin=False)
win = gtk.Window()
win.set_size_request(600,800)
win.add(scroll)
win.show_all()
gtk.main()

test.csv (9.76 KB)

I just ran this on 64-bit linux and didnt see any problems. I do have an issue
with pygtk on my system, but I dont think it is related to mpl:

/usr/lib64/python2.5/site-packages/gtk-2.0/gtk/__init__.py:69: Warning:
ignoring sys.argv: it must be a list of strings
  _gtk.init_check()

···

On Thursday 13 December 2007 11:07:57 am John Hunter wrote:

I moved the tools in mlab that did optional imports (the rec2gtk and
rec2excel functions and their dependencies) out of mlab into
toolkits.gtktools and toolkits.exceltools. As Michael noted, these
imports can be expensive for users with gtk on their system and do not
belong in mlab. In some cases, eg logged in over a dumb terminal with
no x11 but where gtk is present, they also trigger text warnings or
errors from gtk, so are a nuisance. I thought it was worth cleaning
this up for the bugfix release.

If you get a minute to test before the release, that would help -- the
excel part requires pyExcelerator, which is pure python
pyExcelerator download | SourceForge.net

import gtk
import matplotlib.mlab as mlab
import matplotlib.toolkits.gtktools as gtktools
import matplotlib.toolkits.exceltools as exceltools

r = mlab.csv2rec('test.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)

scroll = gtktools.rec2gtk(r, formatd=formatd, autowin=False)
win = gtk.Window()
win.set_size_request(600,800)
win.add(scroll)
win.show_all()
gtk.main()