Events in win32com

Paul Moore paul.moore at uk.origin-it.com
Wed Dec 20 05:50:22 EST 2000


On Wed, 20 Dec 2000 02:11:29 +0100, Mark Hammond
<MarkH at ActiveState.com> wrote:

>Paul Moore wrote:
>
>> After scanning Deja, I found an article describing DispatchWithEvents.
>> The example in the documentation (OnVisible) works fine. But the
>> OnQuit event doesn't seem to work :-( Basically, the event routine is
>> never fired. Is this because the event routine has a ByRef "Cancel"
>> parameter? Or is it something else?
>
>OnQuit works for me.  test\testMSOfficeEvents.py traps this.
>

Grrr. I'm having problems getting events fired from any of the MS
applications (IE, Excel), either in VBScript or in Python. Looks like
it's something stupid I am doing... We'll ignore that for now...

On the other hand, if I use a 3rd party control (WScriptEx) I get
events quite happily in both VBS and Python. But I tried the "return"
trick to set a ByRef parameter, which is shown in
test\testMSOfficeEvents.py, but it doesn't seem to work. I have

    from win32com.client import *

    class WexEvents:
        def OnTick(self, rem, wake):
            print "Tick...", rem, wake
            if rem < 5000:
                # wake = 1 # doesn't work...
                return 1 # Goes into the only ByRef parameter...

    wex = DispatchWithEvents("WshToolbox.WScriptEx", WexEvents)

    print "Zzzzz"
    wex.Sleep(10000,1000)
    print "Hello!"

Here, the WScriptEx Sleep method takes a time to sleep and a time
between ticks, and fires an OnTick event on each tick. The OnTick
event takes a "Remaining Time" (ByVal) parameter, and a "Wake Up"
(ByRef) parameter. My understanding of the example is that returning
1, should set the wake parameter to 1, as it is the only ByRef
parameter and the OnTick event is defined as a sub. But it doesn't
seem to work.

Am I doing something wrong, or is this not expected to work?

Paul




More information about the Python-list mailing list