[IPython-user] ipython -gthread behaviour is now to quit the script gtk.main() loop?
Thu Feb 26 04:39:26 CST 2009
2009/2/26 Fernando Perez <email@example.com>
> Hi Gustavo,
> On Tue, Feb 24, 2009 at 6:50 AM, Gustavo Carneiro <firstname.lastname@example.org>
> > Hello, I have been having a problem since upgrading IPython. I don't
> > remember exactly which version I had before, but now it's 0.8.4.
> > Consider the following script:
> > import gtk
> > win = gtk.Window()
> > win.show()
> > bt = gtk.Button("Hello")
> > bt.show()
> > win.add(bt)
> > print "begin"
> > gtk.main()
> > print "end"
> > In IPython 0.8.4, the gtk.main() call will immediately return and IPython
> > re-runs a new gtk.main(), possibly in a different thread. In a previous
> > version (sorry, don't remember which) my own gtk.main() call would not
> > it would just run the GUI. I was sure that, when gtk.main() returned it
> > because the window had been closed.
> > Now I am unsure how to make it work again. I have module function that
> > supposed to "run the GUI and don't return until everything is finished".
> > Any advice on how to accomplish this without breaking the simple module
> > that I provide? Is there something like,
> > IPython.wait_until_gui_is_finished() ?
> Could you try running the attached script the way you used 'ipython
> -gthread' before? This would help us understand the problem better,
> if this works the way you expect it.
Yeah, more or less. I have to change slightly my strategy. I cannot run
the simulation with ipython -gthread; instead I just run with plain old
python and import IPython module and run the main loop. Taking your code I
# My GUI code
w = gtk.Window()
b = gtk.Button("Hello")
# Run the gtk main loop, with IPython if possible
"""No-op version of the original mainloop hijacker
IPython.Shell.hijack_gtk = hijack_gtk
ip = IPython.Shell.IPShellGTK()
This works perfectly. It is not as "transparent" as before (you could run
ipython -gthread on a unmodified pygtk program), but it does the job nicely.
Maybe if the "hijacked gtk main loop" was the code below my comment "# Run
the gtk main loop, with IPython if possible", then things might be more
transparent for pygtk apps. Because making a gtk.main() a lambda function
that just returns breaks the "blocking main loop" semantics, with possibly
In any case, this provided the needed motivation for me to add a GUI console
to my pygtk app, following the recipe at , which was painless and works
Anyway, thanks for your answer, it has been very useful.
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-user