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

Mark Hammond MarkH at ActiveState.com
Thu Aug 10 20:22:59 EDT 2000


> I'd like to understand why the REAL OnDocumentComplete does not
> happen, if Mark Hammond or somebody else who is really an expert
> can explain (& maybe help us find a better workaround...?),

NFI.  Do we have proof that IE actually fires it?  Maybe it only does
on idle, or something strange?

> but even
> more I'd like to do something about the *Before* events -- and in
> particular to understand how, assuming I manage to get them called,
> I can use their input/output Cancel argument: there seems to be no

All BYREF args can be returned.  In the case of a "void" function with
a single byref, you simply return the new value for this byref.

>From the tutorial I gave at the last conference (powerpoint slides
available from my starship page):

# Demonstrate COM events using Excel
class ExcelEvents:
    def OnSheetBeforeDoubleClick(self, Sh, Target, Cancel):
        if Target.Column % 2 == 0:
            print "You can double-click there..."
            Cancel = 0 # Not setting the ByRef here!
        else:
            print "You can not double-click there..."
            Cancel = 1
        # This function is a void, so the result ends up in
        # the only ByRef - Cancel.
        return Cancel

Mark.





More information about the Python-list mailing list