[IPython-dev] Uniform way of integrating event loops among different IDE's

Almar Klein almar.klein at gmail.com
Mon Aug 30 05:09:30 EDT 2010


On 30 August 2010 09:18, Fernando Perez <fperez.net at gmail.com> wrote:

> Hi Almar,
>
> returning to your original thread, which got a little sidetracked by
> our licensing discussion... :)
> 7
> On Tue, Aug 24, 2010 at 8:06 AM, Almar Klein <almar.klein at gmail.com>
> wrote:
> > I'm developing an IDE for Python (http://code.google.com/p/iep/) that is
> > capable of integrating the event loop of several GUI toolkits. On a side
> > note, I used much code of IPython as inspiration on how to do that, so
> > thanks for that.
> >
> > I saw in the IPython documentation that IPython users can detect whether
> > IPython hijacked the event loop as follows (for wx):
> >
> > try:
> >     from IPython import appstart_wx
> >     appstart_wx(app)
> > except ImportError:
> >      app.MainLoop()
> >
> > A very nifty feature indeed. However, building further on this, wouldn't
> it
> > be nice if people could perform this trick regardless of in which IDE or
> > shell the code is running? Therefore I propose to insert an object in the
> > GUI's module to indicate that the GUI event loop does not need to be
> > entered. I currently use for my IDE:
> >
> > import wx
> > if not hasattr(wx, '_integratedEventLoop'):
> >     app = wx.PySimpleApp()
> >     app.MainLoop()
> >
> > Currently, _integratedEventLoop is a string with the value 'IEP',
> indicating
> > who hijacked the main loop. I'm not sure what IPythons appstart_*
> function
> > does, but the inserted object might just as well be a function that needs
> to
> > be called (using the app instance as an argument, but how to call it for
> > fltk or gtk then?).
> >
> > I'm interested to know what you think of this idea.
>
> Well, Brian just implemented more or less this very same thing:
>
> http://github.com/ipython/ipython/blob/newkernel/IPython/lib/guisupport.py
>
> We decided to call the attribute '_in_event_loop' instead, partly for
> PEP-8 reasons but especially because Enthought was already using that
> name.  Absent a good reason to deviate from their chosen name, which
> is already in a very large codebase, we figured we'd use that.
>
> So let's hope we can get all GUI projects to agree on this approach,
> and it should become possible with only minimal work on the part of
> authors to coexist well with the event loops of various toolkits and
> interactive apps like IPython or IEP.
>

Great. I was not aware of Enthought using this, so I'm happy to adopt that
name instead.

Still, may I suggest the following: IPython or IEP, or any environment,
could inject a function 'start_event_loop' in the module namespace of the
GUI toolkit it integrates. My main argument for this, is that it would be
independent of IPython or any specific library or IDE. The user can then
simply call:

import wx
if hasattr(wx, 'start_event_loop'):
    wx.start_event_loop()
else:
    # Start the "native" way
    app = wx.PySimpleApp(*args, **kwargs)
    app.MainLoop()


Regards,
  Almar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20100830/4f31d58a/attachment.html>


More information about the IPython-dev mailing list