[python-win32] Events in the same object
Rodrigo Strauss
rodrigo at 1bit.com.br
Wed Jul 19 19:33:47 CEST 2006
I need to receive events from a COM object, but using the same object
that's using it (!?), because I need to maintain some state about the
events.
Actually, after calling the Connect method from COM obj, it will fire
the onConnected event after the connection is done. I can call Login
method only after I receive the OnConnect. I need something like this:
class ApiTester:
# events
def OnConnect(self):
self.connection.Logon(uid, pwd)
def OnLogon(self):
print 'ready to go'
def __init__(self):
# self as event sink. Beside circular references, any other problem?
self.connection = DispatchWithEvents("BlaBlaApi.Connection", self)
The above code just give a
"C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 264,
in DispatchWithEvents
result_class = new.classobj("COMEventClass", (disp_class,
events_class, user_event_class), {"__setattr__" : _event_setattr_})
TypeError: instance() takes at most 2 arguments (3 given)
Looking at win32com code, it says it's ok to create a circular
reference between sink and object, as long as I break this calling
close() sometime.
Any idea?
Rodrigo Strauss
More information about the Python-win32
mailing list