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

Almar Klein almar.klein@gmail....
Tue Sep 14 04:20:22 CDT 2010


On 6 September 2010 22:32, Almar Klein <almar.klein@gmail.com> wrote:

>
>
> On 6 September 2010 22:04, Fernando Perez <fperez.net@gmail.com> wrote:
>
>> Hi Almar,
>>
>> On Mon, Sep 6, 2010 at 12:53 PM, Almar Klein <almar.klein@gmail.com>
>> wrote:
>> >
>> > That sounds great! I'll take a look at filling in the blanks for tk,
>> fltk
>> > and gtk if you like.
>>
>> that would be great. Note that as far as we've seen, in light testing
>> it seems that for gtk nothing is needed: with this code on our side:
>>
>>
>> http://github.com/ipython/ipython/blob/newkernel/IPython/zmq/gui/gtkembed.py
>>
>> every single gtk example I've tried so far has worked (with the only
>> caveat being that you have to close them with the window manager
>> buttons rather than the app's own close button/menu).  So we may be
>> home free for gtk, though that's still up for confirmation with more
>> testing and someone more knowledgeable in the matter than me.
>>
>
The code that I use is quite similar to the code behind the link. (Except
that IEP uses its own mainloop in which it periodically calls
gtk.main_iteration().)  In addition to gtk.main() and gtk.main_quit(), I
also replace gtk.mainloop() and gtk.mainquit() with a dummy. I suspect I did
that to also support older versions.



> It also looks like something similar may be OK for tk, where with a
>> bit of hijacking from our side, we can let unmodified Tk code run
>> happily within our own environment.
>>
>> For Qt/Wx it definitely seems that the cooperation via guisupport will
>> be needed.  And for fltk, I have no idea.
>>
>
> I don't think there's much to do for fltk either, I'll look into it
> tomorrow I hope.
>

A bit later than I hoped, but here it goes:

Gtk, Tk, and fltk can all be supported without cooperation via guisupport. I
guess its all about how they define application objects, and in these
toolkits, they're all global. On the kernel side, if integrating the event
loop for these toolkits, you'll need to disable the mainloops. I put some
example code below. Probably nothing new here for you guys, except maybe for
fltk.

Maybe a good idea to put examples such as these in the docs of
guisupport.py?

Cheers,
  Almar


=== Example code for hiding mainloops for TK, FLTK and GTK ===

# Dummy function to replace mainloops with
def dummy(*args,**kwargs):
    pass

# Hijack TK
import Tkinter
Tkinter.Misc.mainloop = dummy
Tkinter.mainloop = dummy

# Create (hidden) root object, to create a Tcl interpreter
r = Tkinter.Tk()
r.withdraw()

# TK events can be processed using:
r.update()


# Hijack FLTK
import fltk
from types import MethodType
fltk.Fl.run = MethodType(dummy, fltk.Fl)

# FLTK events can be processed using:
fltk.Fl.wait(0)


# Hijkack GTK
gtk.mainloop = dummy
gtk.main = dummy
gtk.main_quit = dummy
gtk.mainquit = dummy

# Make sure main_iteration exists even on older versions
if not hasattr(gtk, 'main_iteration'):
    gtk.main_iteration = gtk.mainiteration

# GTK events can be processed using:
while gtk.events_pending():
    gtk.main_iteration(False)

=== End of code ===
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20100914/c41881c3/attachment-0001.html 


More information about the IPython-dev mailing list