Handling Com Events in Python (was Python and Windows Scripting Host)

Syver Enstad syver.enstad at sensewave.com
Wed Aug 9 15:36:14 EDT 2000


..... (On handling Com events in python) Alex Martelli)
> Not trivial.

I thought it was pretty once I used DispatchWithEvents (thanks Mark H.) and
looked at the file lying in gen_py folder. After you have run gen_py look at
the file it has created that lies in the gen_py folder.
Open this file to find the required method signature and copy this to your
class.
(See Hammond, Robinson, Python Programming on Win32, Chapter 12, page 200,
201, 202)

The only problem I have here is that OnDocumentComplete (the most
interesting method) won't compile because the "defaultNamedNotOptArg" label
is unknown to Python. I don't know which module this is located in. Could
anyone help me out here?

Here's the code:

#
#   Ie test
#

import win32com


class EventHandler:
    def OnVisible(self, visible):
        global bVisibleEventFired
        bVisibleEventFired = 1
    def OnDownloadBegin(self):
        print "DownloadBegin"
    def OnDownloadComplete(self):
        print "DownloadComplete"
#    def OnDocumentComplete(self, pDisp=defaultNamedNotOptArg,
URL=defaultNamedNotOptArg):
#        print "documentComplete"


ie = win32com.client.DispatchWithEvents("InternetExplorer.Application",
EventHandler)
ie.Visible = 1
ie.Navigate("www.python.org")

while ie.Visible:
    pass

ie.Quit()







More information about the Python-list mailing list