How To Pass Arguments To Win32com Event Handler
The code below works fine. I can't find a way to pass some arguments to EventHandler or to call methods of MainClass from EventHandler. For example instead of using constant param,
Solution 1:
One possibility is to use WithEvents
function. But this may not be the best way. Also now handler
and client
objects are different entities, so this leads to additional mechanisms of interaction between them.
class EventHandler:
def set_params(self, client):
self.client = client
def OnConnected(self):
print "connected!"
self.client.do_something()
return True
client = win32com.client.Dispatch("Lib.Obj")
handler = win32com.client.WithEvents(client, EventHandler)
handler.set_client(client)
client.connect()
while True:
PumpWaitingMessages()
time.sleep(1)
Here is a complete example.
Post a Comment for "How To Pass Arguments To Win32com Event Handler"