[IPython-dev] GUI support: conflicts between IPython 0.11 and Matplotlib/ETS

Christopher Barker Chris.Barker at noaa.gov
Wed Feb 10 13:15:34 EST 2010


Hi folks,

I'm new to the Ipython dev list, and don't really understand the 
internals, but this thread was posted elsewhere to solicit ideas, so 
here I am:

> One of the
> big new features of 0.11 is a refactored integration with GUI event loops.
> We are very excited about this as it is much more stable and add new
> capabilities, like being able to enable pylab *after* starting IPython (it
> is a magic: %pylab).

very nice.

> Current situation
> =============
> 
> Both matplotlib and ets have code that tries to:
> 
> * See what GUI toolkit is being used
> * Get the global App object if it already exists, if not create it.
> * See if the main loop is running, if not possibly start it.

Are these done in order to support IPython? or for other general usage?

> Description of GUI support in 0.11
> ==========================
> 
> IPython allows GUI event loops to be run in an interactive IPython session.
> This is done using Python's PyOS_InputHook hook which Python calls
> when the :func:`raw_input` function is called and is waiting for user input.

So it doesn't use threads at all? that is good news.

> some
> GUI toolkits, special options have to be passed to the application object
> to enable it to function properly in IPython.

so the app itself needs to do something special? that is too bad -- so 
far, I've found IPython works pretty well with my own wxPython apps, 
with nothing changed in my app.

> * Who is responsible for creating the main GUI application object, IPython
>   or third parties (matplotlib, enthought.traits, etc.)?

I think the third parties -- i.e. you really want to be able to use 
IPython with ANY GUI app - not just one written to be used with IPython.

> * What is the proper way for third party code to detect if a GUI application
>   object has already been created?  If one has been created, how should
>   the existing instance be retrieved?

This is why it seems better for IPython NOT to create the GUI app 
object. If it doesn't, would the third party code have to detect it?

hmm, yes it would, or something -- if I want to call my program with 
"run" more than once, then a wxApp has been initialized already, and I 
think you can only do that once per process.

Could Ipython monkey-patch the GUI toolkits to override the app creation 
and mainloop starting? I'm not sure this is possible, but a typical wx 
app might look like this:

app = wx.App()
app.MainLoop()

if wx had been monkey-patched by IPython, the app creation and mainloop 
calls could be overridden with ones that check to see if they have been 
called before, and do something different if so. As for wx, I don't know 
if you can stop and re-start the mainloop anyway.

I'm still confused how this all seems to work for me with IPython 0.9.1!

I hope this is helpful,

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the IPython-dev mailing list