[python-win32] DispatchWithEvents experiment with subclass event routine and pump messages

Richard Bell rbell01824 at earthlink.net
Fri Jun 1 15:11:33 CEST 2007


This group has been very helpful as I've worked on an IE automation class
(yes I know about Pamie).  I recently encountered a design issue concerning
how to allow users to 'hook' event routines in the IE automation class.
After a bit of thought and scratching around I decided to look into a user
derived event class and ran the following experiment:

>>> import win32com.client
>>> class IEEvents1:
...  def OnVisible(self, visible):
...   print 'Visible changed:', visible
...
>>> ie = win32com.client.DispatchWithEvents(
        'InternetExplorer.Application', IEEvents1)
>>> ie.Visible = 1
Visible changed: True
>>> ie.Navigate('www.google.com')
>>>

Then I subclassed the event routine and played some more:

>>> class IEEvents2(IEEvents1):
...  def OnDocumentComplete(self, pDisp, url):
...   print 'Top %s pDisp %s url %s'% \
...                   (pDisp==self,pDisp,url)
...  
>>> ie2 = win32com.client.DispatchWithEvents(
         'InternetExplorer.Application', IEEvents2)
>>> ie2.Visible = 1
Visible changed: True
>>> ie2.Navigate('www.citizensbank.com')
>>> Top False pDisp 
       url http://www.citizensbank.com/scripts/tc/logging.html
   Top False pDisp 
       url http://www.citizensbank.com/olblogin/olblogin.aspx?f=p7X03No2hg
   Top True pDisp 
       url http://www.citizensbank.com/home/

I see both the Visible event from IEEvents1 AND the DocumentComplete event
from IEEvents2. So subclassing apparently works and the issue of user hooks
into the event interface is resolved rather neatly via classes.  That's cool
but ...

Who/what ran the message pump during the experiment or do I not really
understand the message pump?

Anyone have any insight?

Regards,
Richard



More information about the Python-win32 mailing list