How to consume COM events from python modules generated using makepy? I instance of Test works but how to implement events?
class ITest(DispatchBaseClass): 'Dispatch-Interface for the Test object' CLSID = IID('{F0691CAD-0C9D-4357-9373-CE6972E1F8A5}') coclass_clsid = IID('{E4A22390-5A45-4217-AD46-EA4E4EBBEA79}') ... ... ... def __iter__(self): "Return a Python iterator for this object" try: ob = self._oleobj_.InvokeTypes(-4,LCID,3,(13, 10),()) except pythoncom.error: raise TypeError("This object does not support enumeration") return win32com.client.util.Iterator(ob, None) class ITest_Events: 'Event-Interface for the Test objects' CLSID = CLSID_Sink = IID('{7556E550-8FA7-424D-B9AD-600B9E8E983A}') coclass_clsid = IID('{E4A22390-5A45-4217-AD46-EA4E4EBBEA79}') _public_methods_ = [] # For COM Server support _dispid_to_func_ = { 1 : "OnRunProject", } def __init__(self, oobj = None): if oobj is None: self._olecp = None else: import win32com.server.util from win32com.server.policy import EventHandlerPolicy cpc=oobj._oleobj_.QueryInterface(pythoncom.IID_IConnectionPointContainer) cp=cpc.FindConnectionPoint(self.CLSID_Sink) cookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy)) self._olecp,self._olecp_cookie = cp,cookie def __del__(self): try: self.close() except pythoncom.com_error: pass def close(self): if self._olecp is not None: cp,cookie,self._olecp,self._olecp_cookie = self._olecp,self._olecp_cookie,None,None cp.Unadvise(cookie) def _query_interface_(self, iid): import win32com.server.util if iid==self.CLSID_Sink: return win32com.server.util.wrap(self) # Event Handlers # If you create handlers, they should have the following prototypes: # def OnRunProject(self): # 'This event is fired when the project starts to run.' Any help will be much appreciated.
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32