<br><br><div class="gmail_quote">On 6 September 2010 22:32, Almar Klein <span dir="ltr"><<a href="mailto:almar.klein@gmail.com">almar.klein@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><br><div class="gmail_quote"><div><div></div><div class="h5">On 6 September 2010 22:04, Fernando Perez <span dir="ltr"><<a href="http://fperez.net" target="_blank">fperez.net</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Almar,<br>
<div><br>
On Mon, Sep 6, 2010 at 12:53 PM, Almar Klein <<a href="mailto:almar.klein@gmail.com" target="_blank">almar.klein@gmail.com</a>> wrote:<br>
><br>
> That sounds great! I'll take a look at filling in the blanks for tk, fltk<br>
> and gtk if you like.<br>
<br>
</div>that would be great. Note that as far as we've seen, in light testing<br>
it seems that for gtk nothing is needed: with this code on our side:<br>
<br>
<a href="http://github.com/ipython/ipython/blob/newkernel/IPython/zmq/gui/gtkembed.py" target="_blank">http://github.com/ipython/ipython/blob/newkernel/IPython/zmq/gui/gtkembed.py</a><br>
<br>
every single gtk example I've tried so far has worked (with the only<br>
caveat being that you have to close them with the window manager<br>
buttons rather than the app's own close button/menu).  So we may be<br>
home free for gtk, though that's still up for confirmation with more<br>
testing and someone more knowledgeable in the matter than me.<br></blockquote></div></div></div></blockquote><div><br>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.<br>
<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

It also looks like something similar may be OK for tk, where with a<br>
bit of hijacking from our side, we can let unmodified Tk code run<br>
happily within our own environment.<br>
<br>
For Qt/Wx it definitely seems that the cooperation via guisupport will<br>
be needed.  And for fltk, I have no idea.<br></blockquote></div></div><div><br>I don't think there's much to do for fltk either, I'll look into it tomorrow I hope. <br></div></div></blockquote><div><br>A bit later than I hoped, but here it goes:<br>
<br>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. <br>
<br>Maybe a good idea to put examples such as these in the docs of guisupport.py?<br><br>Cheers,<br>  Almar<br><br><br>=== Example code for hiding mainloops for TK, FLTK and GTK ===<br><br># Dummy function to replace mainloops with<br>
def dummy(*args,**kwargs):<br>    pass<br><br># Hijack TK<br>import Tkinter<br>Tkinter.Misc.mainloop = dummy<br>Tkinter.mainloop = dummy<br><br># Create (hidden) root object, to create a Tcl interpreter<br>r = Tkinter.Tk()<br>
r.withdraw()<br><br># TK events can be processed using:<br>r.update()<br><br><br># Hijack FLTK<br>import fltk<br>from types import MethodType<br>fltk.Fl.run = MethodType(dummy, fltk.Fl)<br><br># FLTK events can be processed using:<br>
fltk.Fl.wait(0)<br><br><br># Hijkack GTK<br>gtk.mainloop = dummy<br>gtk.main = dummy<br>gtk.main_quit = dummy<br>gtk.mainquit = dummy<br><br># Make sure main_iteration exists even on older versions<br>if not hasattr(gtk, 'main_iteration'):<br>
    gtk.main_iteration = gtk.mainiteration<br><br># GTK events can be processed using:<br>while gtk.events_pending():            <br>    gtk.main_iteration(False)<br><br>=== End of code ===<br></div></div><br><br>