[Twisted-Python] Excel, Twisted, and wxPython

Uwe C. Schroeder uwe at oss4u.com
Sun Jun 1 04:57:06 EDT 2003


Well, I have no idea if you can get this working, but here are my $0.02

The problem with twisted and wx is that both systems are event driven and both 
have a never-ending mainloop to process those events.
As you figured out already, wx is particularly weird with event loops. The wx 
MainLoop processes only non-modal UI events. The moment you open a modal 
window (or a pulldown menu) the mainloop stops looping and waits for some 
"sub-loop" to terminate. Unfortunately this sub-loop depends on the platform 
you are on. AFAIK wxWindows simply uses the loops from the different toolkits 
(GTK, MS ....), so there is basically no way to hook into those loops in a 
platform independant way. Maybe Robin can shed some light on this.

This is also the problem with the twisted wx support code. It works nicely as 
long as you don't use a modal window. Then the code simply stops working. 
That's why I posted a recipe on activestate's python cookbook, which uses a 
timer to run the twisted reactor without actually running the reactor loop. 
This is the only way I could get it working without using threads and as I 
see in your Python2 file you figured that one out.

I am not sure what the wxApp Mainloop does internally. Maybe you try calling 
the Dispatch and ProcessIdle methods once in a while, or dig into the source 
and figure out what they do internally. My guess would be that some UI events 
aren't processed properly.
Another wild idea that just jumped to my mind. Try an event.Skip() at the end 
of you OnIdle handler.  Maybe there is some other internal idle event handler 
that never gets called since you have your own and thus you miss some 
internal handling.

Not much, but maybe it helps.


On Sunday 01 June 2003 12:23 am, Andrew Dalke wrote:
> Hi,
>
>    I'm working on an add-in for Excel, under MS Windows.  This takes
> information
> from the current selection and uses XML-RPC to call a remote server.
>
>    The call may take a while, so I want to have a "Cancel" button.  I
> decided to use wxPython for the GUI, with a modal dialog.  Basically,
> a wxGauge (for the progress bar) and a "Cancel" button.
>
>    The RPC call itself may take several minutes, so I need to use either
> threads or Twisted, and obviously I decided on the latter.  (This is an
> in-process add-in; I'm worried about using threads inside the Excel
> process itself.)
>
>    I can't figure out how to make this all work together.  There's some
> support code in Twisted for wxPython, but it appears to only support
> the main event loop, while I'm running a modal window, and never call
> my wxApp's MainLoop.
>
>    I tried replacing my wxDialog with a wxFrame, which kinda works,
> except
> that the background is very strange.  It looks like it hasn't been
> fully initialized.
>
>    I've attached my code, in the hopes that someone here can help me
> figure out what to do.
>
>    BTW, Twisted's wxPython support subsumes wx's main loop code.  Is
> there any reason there can't be an implementation which hooks into
> wx's idle loop, so that users can decide who's in charge?  I think that
> would actually fix my problem, since Modals (I think) process the
> idle loop ...  Nope, I'm not clever enough to figure that out - my
> attempt is attached as "Progress2.py"
>
> 					Andrew
> 					dalke at dalkescientific.com


--
Open Source Solutions 4U, LLC	2570 Fleetwood Drive
Phone:  +1 650 872 2425		San Bruno, CA 94066
Cell:   +1 650 302 2405		United States
Fax:    +1 650 872 2417





More information about the Twisted-Python mailing list