[IPython-dev] Re: [SciPy-dev] Generic gui_thread + IPython: solution already exists!
prabhu_r at users.sf.net
Mon Nov 15 05:33:08 EST 2004
>>>>> "FP" == Fernando Perez <Fernando.Perez at colorado.edu> writes:
>> I can send you a patch for the wxPython stuff and the
>> preliminary work for gtk. I think John will have to fix the
>> pyGTK code a little more since he obviously knows a lot more
>> than me about pyGTK.
FP> Sure, pass me the patch. Hopefully John, or someone else, can
FP> take a stab at this at so the pygtk stuff works as well. I'll
FP> give it a try myself, but since I've never used pygtk, I'm
FP> quite likely to miss even obvious stuff.>
Attached is a patch for IPython/Shell.py. The diff is against the CVS
version of Shell.py. A summary of what I've done:
* Enabled the -wthread (for wx) and -gthread (for gtk) options. This
means you don't need to do -pylab and setup the .matplotlibrc if
you don't need it.
* Hijack all relevant mainloops that I am aware of for wx and gtk.
The wxPython support should work for both 2.4.x and 2.5.x. My
simple tests for gtk also work just fine. So I think we have gtk
covered as well.
* BONUS: I also added support so you can script Tkinter apps when you
use either -wthread or -gthread! This necessitates importing
Tkinter at startup time, but that takes so little time, that I
thought it not worth adding yet another command line option.
Anyway, what this means is that you can actually use
matplotlib/wxPython/pygtk apps *and* MayaVi at the *same* time. It
all seems to work really nicely. :)
It is NOT possible to run both wxPython and pyGTK apps together.
Doing so will leave you with serious problems (most likely segfaults
and core files). Tkinter works well with either. While this might
not be a big deal (it certainly is not a big deal for me), it would be
nice if this were handled.
I have a crude idea to work around this by simply creating two
threads, one for wx and one for gtk. We have two possibilities:
1. The user has to request that the command be executed in the
appropriate thread. Something like this::
Message: WX thread is default
>>> %gtk_thread: w.show_all()
Message: GTK thread is default
>>> %wx_thread: d.Show(1)
2. When interpreting the code, check the types of the objects being
used and send code to appropriate thread. I would think this is a
painful way, plus you can't handle cases where both gtk and wx
objects are used.
Option 1 allows the user to blow up the Python session to bits if he
does the wrong thing. However, it makes it possible to run GTK, WX
and Tkinter apps interactively! Definitely worth bragging about. ;-)
In any case, the attached patch is as far as I am willing to go. I
currently don't need to run wxPython and gtk apps simultaneously and
am unlikely to run into this situation in the near future. So, I'll
let you think about the other issues.
BTW, Fernando, did you get to post the modified python-mode.el to the
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the IPython-dev