[python-win32] DispatchWithEvents design question

Richard Bell rbell01824 at earthlink.net
Fri Jun 8 01:57:55 CEST 2007


Tim Roberts wrote
|It's quite possible for a single callback to happen both synchronously
|and asynchronously, depending on context.  In this case, IE probably
|considers the StatusBar to be one of its "commands", so the
|OnCommandStateChange makes some sense.

Is it then the case that my OnEvent routines should only execute under one
of the following conditions?

1 - I interact with the COM target as in ie.Visible = 1 or ie.Navigate2
2 - I execute a pythoncom.PumpWaitingMessages

In particular, under no circumstances will my On-event routines execute
(apartment-threaded early binding) so that for example:

# On-event routines might run across this
Ie.Visible = 1 
# But once I get here On-event routines will NOT run
...
# On-event routines might run across this
Ie.Navigate2('www.google.com')
# But once I get here On-event routines will NOT run
...
tT0 = time.clock()
# On-event routines might run across this
while time.clock()-t0<10: pythoncom.PumpWaitingMessages
# But once I get here On-event routines will NOT run

In particular, is it true if I'm automating IE and the user moves or resizes
the browser window or some other action that caused events then those events
will queue and my OnEvent routines will NOT run until such time as I again
interact with COM or pump messages?  Thus when I'm not interacting
explicitly with COM (apartment-threaded) unanticipated On-event routine
execution is NOT possible.

One of the reasons I'm focusing on this is that I noticed in the last
example that events WERE queued and only became visible when messages were
pumped.  It seems to me that that in turn means that after my code gets
control back and I go off and do whatever then when I once again want to
interact with IE and COM I'd best pump messages FIRST to insure that any
pending messages are flushed from the queue (at least if my new interactions
depend on the future message flow as they do) since some agency outside my
program (the user or a bit of script on the page) may have done things that
caused events that are NOT associated with my pending interaction.

Thanks again for your assistance, it is very valuable and has helped clear
up a number of areas I really didn't understand very well.  As you might
have gathered from the questions, the answers have some fairly consequential
design impacts that were certainly not apparent to me based on my initial
understanding (or more properly lack of understanding).

BTW, my offer of an example still stands and I think I may finally have
enough of an understanding to post something if it would be helpful to
others.

Regards,
Richard 



More information about the Python-win32 mailing list