On 6/11/2009 11:09 AM, Celvin wrote: ...
class application(object): def __init__(self): self.__com_obj = DispatchWithEvents("{GUID}", event_handler) self.__objects = []def register(self, obj): self.__objects.append(obj) Basically, I'm trying to manage a list of objects returned via a call to a COM object, so that I can access them at later times in Python code and to keep them referenced so that the event handler won't get disconnected when Python determines the object is no longer in use. (getevents() alone isn't an option here as it wouldn't solve the problem of accessing the application object everywhere I need it).
Can't you set an attribute on __com_obj after creation?
The real application class is obviously more complex and contains data I need in the event handler. First thing is, I can't think of a clean way to provide event_handler with a reference to an application instance without using globals (ugly), and second, even if I could access an application instance in event_handler, I'm wondering if this wouldn't create a circular reference (i.e. the event handler class would maintain a reference to the COM object via application.__com_obj, while the COM object maintains a reference to the event handler, established via DispatchWithEvents - I don't know if the EventProxy class would somehow prevent this).
Yeah, circular refs are a bit of a problem - event handlers have a way of disconnecting though - you may need to dog into the source to best work out how to hook into that process.
Cheers, Mark _______________________________________________ python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
