PyXR

c:\python24\lib\site-packages\win32 \ com \ client \ connect.py



0001 """Utilities for working with Connections"""
0002 import win32com.server.util, pythoncom
0003 
0004 class SimpleConnection:
0005         "A simple, single connection object"
0006         def __init__(self, coInstance = None, eventInstance = None, eventCLSID = None, debug = 0):
0007                 self.cp = None
0008                 self.cookie = None
0009                 self.debug = debug
0010                 if not coInstance is None:
0011                         self.Connect(coInstance , eventInstance, eventCLSID)
0012 
0013         def __del__(self):
0014                 try:
0015                         self.Disconnect()
0016                 except pythoncom.error:
0017                         # Ignore disconnection as we are torn down.
0018                         pass
0019 
0020         def _wrap(self, obj):
0021                 useDispatcher = None
0022                 if self.debug:
0023                         from win32com.server import dispatcher
0024                         useDispatcher = dispatcher.DefaultDebugDispatcher
0025                 return win32com.server.util.wrap(obj, useDispatcher=useDispatcher)
0026 
0027         def Connect(self, coInstance, eventInstance, eventCLSID = None):
0028                 try:
0029                         oleobj = coInstance._oleobj_
0030                 except AttributeError:
0031                         oleobj = coInstance
0032                 cpc=oleobj.QueryInterface(pythoncom.IID_IConnectionPointContainer)
0033                 if eventCLSID is None: eventCLSID = eventInstance.CLSID
0034                 comEventInstance = self._wrap(eventInstance)
0035                 self.cp=cpc.FindConnectionPoint(eventCLSID)
0036                 self.cookie = self.cp.Advise(comEventInstance)
0037 
0038         def Disconnect(self):
0039                 if not self.cp is None:
0040                         if self.cookie:
0041                                 self.cp.Unadvise(self.cookie)
0042                                 self.cookie = None
0043                         self.cp = None                
0044 

Generated by PyXR 0.9.4
SourceForge.net Logo