我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用pythoncom.IID_IConnectionPointContainer()。
def Connect(self, coInstance, eventInstance, eventCLSID = None): try: oleobj = coInstance._oleobj_ except AttributeError: oleobj = coInstance cpc=oleobj.QueryInterface(pythoncom.IID_IConnectionPointContainer) if eventCLSID is None: eventCLSID = eventInstance.CLSID comEventInstance = self._wrap(eventInstance) self.cp=cpc.FindConnectionPoint(eventCLSID) self.cookie = self.cp.Advise(comEventInstance)
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 WriteEventSinkClassHeader(self, generator): generator.checkWriteEventBaseClass() doc = self.doc stream = generator.file print >> stream, 'class ' + self.python_name + ':' if doc[1]: print >> stream, '\t' + build._makeDocString(doc[1]) try: progId = pythoncom.ProgIDFromCLSID(self.clsid) print >> stream, "\t# This class is creatable by the name '%s'" % (progId) except pythoncom.com_error: pass print >> stream, '\tCLSID = CLSID_Sink = ' + repr(self.clsid) if self.coclass_clsid is None: print >> stream, "\tcoclass_clsid = None" else: print >> stream, "\tcoclass_clsid = " + repr(self.coclass_clsid) print >> stream, '\t_public_methods_ = [] # For COM Server support' WriteSinkEventMap(self, stream) print >> stream print >> stream, '\tdef __init__(self, oobj = None):' print >> stream, "\t\tif oobj is None:" print >> stream, "\t\t\tself._olecp = None" print >> stream, "\t\telse:" print >> stream, '\t\t\timport win32com.server.util' print >> stream, '\t\t\tfrom win32com.server.policy import EventHandlerPolicy' print >> stream, '\t\t\tcpc=oobj._oleobj_.QueryInterface(pythoncom.IID_IConnectionPointContainer)' print >> stream, '\t\t\tcp=cpc.FindConnectionPoint(self.CLSID_Sink)' print >> stream, '\t\t\tcookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy))' print >> stream, '\t\t\tself._olecp,self._olecp_cookie = cp,cookie' print >> stream, '\tdef __del__(self):' print >> stream, '\t\ttry:' print >> stream, '\t\t\tself.close()' print >> stream, '\t\texcept pythoncom.com_error:' print >> stream, '\t\t\tpass' print >> stream, '\tdef close(self):' print >> stream, '\t\tif self._olecp is not None:' print >> stream, '\t\t\tcp,cookie,self._olecp,self._olecp_cookie = self._olecp,self._olecp_cookie,None,None' print >> stream, '\t\t\tcp.Unadvise(cookie)' print >> stream, '\tdef _query_interface_(self, iid):' print >> stream, '\t\timport win32com.server.util' print >> stream, '\t\tif iid==self.CLSID_Sink: return win32com.server.util.wrap(self)' print >> stream self.bWritten = 1
def WriteEventSinkClassHeader(self, generator): generator.checkWriteEventBaseClass() doc = self.doc stream = generator.file print('class ' + self.python_name + ':', file=stream) if doc[1]: print('\t' + build._makeDocString(doc[1]), file=stream) try: progId = pythoncom.ProgIDFromCLSID(self.clsid) print("\t# This class is creatable by the name '%s'" % (progId), file=stream) except pythoncom.com_error: pass print('\tCLSID = CLSID_Sink = ' + repr(self.clsid), file=stream) if self.coclass_clsid is None: print("\tcoclass_clsid = None", file=stream) else: print("\tcoclass_clsid = " + repr(self.coclass_clsid), file=stream) print('\t_public_methods_ = [] # For COM Server support', file=stream) WriteSinkEventMap(self, stream) print(file=stream) print('\tdef __init__(self, oobj = None):', file=stream) print("\t\tif oobj is None:", file=stream) print("\t\t\tself._olecp = None", file=stream) print("\t\telse:", file=stream) print('\t\t\timport win32com.server.util', file=stream) print('\t\t\tfrom win32com.server.policy import EventHandlerPolicy', file=stream) print('\t\t\tcpc=oobj._oleobj_.QueryInterface(pythoncom.IID_IConnectionPointContainer)', file=stream) print('\t\t\tcp=cpc.FindConnectionPoint(self.CLSID_Sink)', file=stream) print('\t\t\tcookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy))', file=stream) print('\t\t\tself._olecp,self._olecp_cookie = cp,cookie', file=stream) print('\tdef __del__(self):', file=stream) print('\t\ttry:', file=stream) print('\t\t\tself.close()', file=stream) print('\t\texcept pythoncom.com_error:', file=stream) print('\t\t\tpass', file=stream) print('\tdef close(self):', file=stream) print('\t\tif self._olecp is not None:', file=stream) print('\t\t\tcp,cookie,self._olecp,self._olecp_cookie = self._olecp,self._olecp_cookie,None,None', file=stream) print('\t\t\tcp.Unadvise(cookie)', file=stream) print('\tdef _query_interface_(self, iid):', file=stream) print('\t\timport win32com.server.util', file=stream) print('\t\tif iid==self.CLSID_Sink: return win32com.server.util.wrap(self)', file=stream) print(file=stream) self.bWritten = 1