return code from win32event.WaitForMultipleObjects()

Miranda Evans mirandacascade at yahoo.com
Mon May 20 13:46:43 EDT 2002


I do not understand why win32event.WaitForMultipleObjects is returning
the values that it is returning in this example.

Using one of the events from testMSOfficeEvents.py as the basis for
this
test, I created test_demo.py.  Using python 2.2; O/S is Windows 2000;
using PythonWin.

contents of test_demo.py are:

import time, win32event, win32com.client, pythoncom
class xlEv:
   def __init__(self):
      self.event = win32event.CreateEvent(None, 0, 0, None)
   def OnSheetBeforeDoubleClick(self, sh, target, cancel):
      print 'double click happened'
      win32event.SetEvent(self.event)

def demo():
   g = xlEv()
   xl=win32com.client.DispatchWithEvents("Excel.Application", xlEv)
   xl.Visible=1
   xl.Workbooks.Add()
   start_time = time.time()
   while 1:
      rc = win32event.WaitForMultipleObjects((g.event,),
           0, 1000, win32event.QS_ALLEVENTS)
      if rc == win32event.WAIT_OBJECT_0:
         print 'event signalled'
         break
      elif rc == win32event.WAIT_OBJECT_0+1:
         pythoncom.PumpWaitingMessages()
      # check for timeout
      if time.time() - start_time > 15:
         print 'timed out'
         break

Then in PythonWin
>>> import test_demo
>>> test_demo.demo()

< at this point, I double click in a cell in the Excel app and go back
to PythonWin>

>>> double click happened
>>> timed out

Since the message 'double click happened' appears, I'm assuming that
the code in the OnSheetBeforeDoubleClick() method got executed, and
I'm assuming that the following statement in the
OnSheetBeforeDoubleClick() method:

win32event.SetEvent(self.event)

got executed.  Additionally, I would have expected that the SetEvent
would have resulted in a return code of win32event.WAIT_OBJECT_0
within the while loop.  It doesn't appear as though a return code of
win32event.WAIT_OBJECT_0 is ever encountered in the while loop. 
Assuming I want the while loop to terminate as soon as the double
click happens, how should I set up the program to handle this type of
notification?



More information about the Python-list mailing list