mhammond at skippinet.com.au
Fri Apr 4 01:12:03 CEST 2003
Miranda Evans wrote:
> In the following code, the while loop is written such that it
> terminates when either the double click event in the Excel object
> happens or ten seconds has elapsed...whichever comes first.
> import time, win32event, win32com.client, pythoncom
> class xlEv:
> def OnSheetBeforeDoubleClick(self, sh, target, cancel):
> def demo():
> xl=win32com.client.DispatchWithEvents("Excel.Application", xlEv)
> xl.event = win32event.CreateEvent(None, 0, 0, None) # work around
> start_time = time.time()
> while 1:
> rc = win32event.MsgWaitForMultipleObjects((xl.event,),
> 0, 1000, win32event.QS_ALLEVENTS)
> if rc == win32event.WAIT_OBJECT_0:
> print 'event signalled'
> elif rc == win32event.WAIT_OBJECT_0+1:
> # check for timeout
> if time.time() - start_time > 15:
> print 'timed out'
> Suppose I want to augment the demo() method so that it continues to do
> what it's already doing (waiting for either the double click event or
> for 10 seconds to elapse) plus one more thing: if the double click
> event is detected, display the values of the sh, target and cancel
> How would one modify the demo() method to do that?
You would would create a new win32event object, and the double-click
handler would set this event. The main loops MsgWaitForMultipleObjects
would get two events passed as the first param - this would make
WAIT_OBJECT_0+1 your new event, and WAIT_OBJECT_0+2 now the "message
More information about the Python-list