home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2640 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.0 KB  |  63 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32com.server.util as win32com
  5. import pythoncom
  6.  
  7. class SimpleConnection:
  8.     
  9.     def __init__(self, coInstance = None, eventInstance = None, eventCLSID = None, debug = 0):
  10.         self.cp = None
  11.         self.cookie = None
  12.         self.debug = debug
  13.         if coInstance is not None:
  14.             self.Connect(coInstance, eventInstance, eventCLSID)
  15.         
  16.  
  17.     
  18.     def __del__(self):
  19.         
  20.         try:
  21.             self.Disconnect()
  22.         except pythoncom.error:
  23.             pass
  24.  
  25.  
  26.     
  27.     def _wrap(self, obj):
  28.         useDispatcher = None
  29.         if self.debug:
  30.             dispatcher = dispatcher
  31.             import win32com.server
  32.             useDispatcher = dispatcher.DefaultDebugDispatcher
  33.         
  34.         return win32com.server.util.wrap(obj, useDispatcher = useDispatcher)
  35.  
  36.     
  37.     def Connect(self, coInstance, eventInstance, eventCLSID = None):
  38.         
  39.         try:
  40.             oleobj = coInstance._oleobj_
  41.         except AttributeError:
  42.             oleobj = coInstance
  43.  
  44.         cpc = oleobj.QueryInterface(pythoncom.IID_IConnectionPointContainer)
  45.         if eventCLSID is None:
  46.             eventCLSID = eventInstance.CLSID
  47.         
  48.         comEventInstance = self._wrap(eventInstance)
  49.         self.cp = cpc.FindConnectionPoint(eventCLSID)
  50.         self.cookie = self.cp.Advise(comEventInstance)
  51.  
  52.     
  53.     def Disconnect(self):
  54.         if self.cp is not None:
  55.             if self.cookie:
  56.                 self.cp.Unadvise(self.cookie)
  57.                 self.cookie = None
  58.             
  59.             self.cp = None
  60.         
  61.  
  62.  
  63.