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

Brian Granger ellisonbg.net@gmail....
Tue Feb 9 22:59:55 CST 2010


Hello all,

As many of you know, we have been working hard on IPython 0.11.  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).

BUT, as Fernando and I have started to use the IPython 0.11 alpha for our
daily work, we have found some subtle issue with IPython 0.11 and the
current
versions of matplotlib and Enthought tool suite (traits, chaco, mayavi).
All of these packages rely on IPython's previous way of handling GUI
integration.  Because of this, current versions of matplotlib and ets don't
work fully with IPython 0.11.  In some cases, they work OK, but there are a
whole class
of bugs that keep popping up.  We don't want to release IPython 0.11 until
these issues are resolved.

All of these bugs are related to a few aspects of creating the main GUI app
objects and starting event loops.  We think we understand the issues, but we
will
need to work with the devs of matplotlib and ets to decide on how we all
want to handle these things.  Here is where we are at...

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.

All of this logic makes many assumptions about how IPython affects the
answers to these
questions.  Because IPython's GUI support has changed in significant ways,
current matplotlib
and ets make incorrect decisions about these issues (such as trying to start
the event loop
a second time, creating a second main App ojbect, etc.) under IPython 0.11.
This leads to crashes...

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.
IPython has versions of this hook for wx, pyqt4 and pygtk.  When the
inputhook
is called, it iterates the GUI event loop until a user starts to type
again.  When
the user stops typing, the event loop iterates again.  This is how tk works.

When a GUI program is used interactively within IPython, the event loop of
the GUI should *not* be started. This is because, the PyOS_Inputhook itself
is responsible for iterating the GUI event loop.

IPython has facilities for installing the needed input hook for each GUI
toolkit and for creating the needed main GUI application object. Usually,
these main application objects should be created only once and for some
GUI toolkits, special options have to be passed to the application object
to enable it to function properly in IPython.

What we need to decide
===================

We need to answer the following questions:

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

* 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?

* In a GUI application object has been created, how should third party code
  detect if the GUI event loop is running. It is not sufficient to call the
  relevant function methods in the GUI toolkits (like ``IsMainLoopRunning``)
  because those don't know if the GUI event loop is running through the
  input hook.

* We might need a way for third party code to determine if it is running
  in IPython or not.  Currently, the only way of running GUI code in IPython
  is by using the input hook, but eventually, GUI based versions of IPython
  will allow the GUI event loop in the more traditional manner. We will need
  a way for third party code to distinguish between these two cases.

Thanks for participating in this discussion!

Cheers,

Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20100209/e39a4482/attachment-0001.html 


More information about the IPython-dev mailing list