Servicing events from a COM server
Syver Enstad
syver-en+usenet at online.no
Thu Mar 6 07:16:35 EST 2003
jbrydon at precisiondesign.com.au (John Brydon) writes:
> Sorry - I don't seem to have made myself clear. The COM object is
> happily working as an out-of process server but I need a way of
> passing to it the location of a function written in Python script so
> that the script can service an event originating in the COM. Were I
> doing this all in C++, for example, I would be passing to the COM
> object a pointer to my external (client) function. Writing this in
> Python, however, I can't see how to do this.
Here is an example that services InternetExplorer events
import win32gui
import win32com
import win32com.client
import pythoncom
import time
class EventHandler:
def OnVisible(self, visible):
global bVisibleEventFired
bVisibleEventFired = 1
def OnDownloadBegin(self):
print "DownloadBegin"
def OnDownloadComplete(self):
print "DownloadComplete"
def OnDocumentComplete(self, pDisp = pythoncom.Missing , URL = pythoncom.Missing):
print "documentComplete of %s" % URL
ie = win32com.client.DispatchWithEvents("InternetExplorer.Application", EventHandler)
ie.Visible = 1
ie.Navigate("www.hegnar.no")
# Important you have to pump messages in some way, because the
# COM event mechanism depends on using window messages to dispatch
# incoming calls
print pythoncom.PumpMessages()
#~ while ie.Visible:
#~ time.sleep(2)
#~ print 'looping'
ie.Quit()
--
Vennlig hilsen
Syver Enstad
More information about the Python-list
mailing list