Gtk stuff in mlab.py

There are some Gtk-specific functions at the bottom of mlab.py. It tries to "import gtk" and then will either define them or not.

On one of my recent profiling fests, I noticed that this "import gtk" (if gtk is installed, and running with some non-Gtk backend) accounts for between 1-2% of the total running time over all the examples in backend_driver.py. Not a huge amount, but it seems like it might be a good idea to avoid importing something as large as gtk unless we actually need to.

We can either import gtk "on demand", when one of these gtk-related functions is called, or perhaps better yet move this to another module, that would only be imported when needed. In light of recent pylab.py/mlab.py refactorings, are there any opinions on this?

Cheers,
Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Ahh, I hadn't considered import time in the try/except block. In
light of this, we probably will want to put them in another module. I
was inclined to something like matplotlib.gui.gtktools, but tere is
an analogous problem with mlab.rec2excel which conditionally imports
pyExcelerator (you probably did not notice it in your timing since it
wasn't installed). Perhaps matplotlib.external or
matplotlib.optional as top-level packages for both (and related).
Something like

matplotlib.optional.exceltools
matplotlib.optional.gtktools

This will serve the dual purpose of cleaning mlab and making Jarrod's
job a bit easier when he decides what to bring over to scipy.

JDH

···

On Nov 29, 2007 2:30 PM, Michael Droettboom <mdroe@...31...> wrote:

There are some Gtk-specific functions at the bottom of mlab.py. It
tries to "import gtk" and then will either define them or not.