home *** CD-ROM | disk | FTP | other *** search
/ Freelog 116 / FreelogNo116-JuilletSeptembre2013.iso / Bureautique / gImageReader / gimagereader_0.9-1_win32.exe / bin / win32com / client / selecttlb.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2011-03-24  |  5KB  |  172 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Utilities for selecting and enumerating the Type Libraries installed on the system
  5. '''
  6. import win32api
  7. import win32con
  8. import pythoncom
  9.  
  10. class TypelibSpec:
  11.     
  12.     def __init__(self, clsid, lcid, major, minor, flags = 0):
  13.         self.clsid = str(clsid)
  14.         self.lcid = int(lcid)
  15.         self.major = major
  16.         self.minor = minor
  17.         self.dll = None
  18.         self.desc = None
  19.         self.ver_desc = None
  20.         self.flags = flags
  21.  
  22.     
  23.     def __getitem__(self, item):
  24.         if item == 0:
  25.             return self.ver_desc
  26.         raise None('Cant index me!')
  27.  
  28.     
  29.     def __lt__(self, other):
  30.         me = (None, ''.lower() if not self.ver_desc else ''.lower(), self.major, self.minor)
  31.         them = (None, ''.lower() if not other.ver_desc else ''.lower(), other.major, other.minor)
  32.         return me < them
  33.  
  34.     
  35.     def __eq__(self, other):
  36.         if None == ''.lower() if not self.ver_desc else ''.lower() and None == ''.lower() if not self.desc else ''.lower() and self.major == other.major:
  37.             pass
  38.         return self.minor == other.minor
  39.  
  40.     
  41.     def Resolve(self):
  42.         if self.dll is None:
  43.             return 0
  44.         tlb = None.LoadTypeLib(self.dll)
  45.         self.FromTypelib(tlb, None)
  46.         return 1
  47.  
  48.     
  49.     def FromTypelib(self, typelib, dllName = None):
  50.         la = typelib.GetLibAttr()
  51.         self.clsid = str(la[0])
  52.         self.lcid = la[1]
  53.         self.major = la[3]
  54.         self.minor = la[4]
  55.         if dllName:
  56.             self.dll = dllName
  57.  
  58.  
  59.  
  60. def EnumKeys(root):
  61.     index = 0
  62.     ret = []
  63.     while None:
  64.         
  65.         try:
  66.             item = win32api.RegEnumKey(root, index)
  67.         except win32api.error:
  68.             break
  69.  
  70.         
  71.         try:
  72.             val = win32api.RegQueryValue(root, item)
  73.         except win32api.error:
  74.             val = ''
  75.  
  76.         index = index + 1
  77.         continue
  78.         return ret
  79.  
  80. FLAG_RESTRICTED = 1
  81. FLAG_CONTROL = 2
  82. FLAG_HIDDEN = 4
  83.  
  84. def EnumTlbs(excludeFlags = 0):
  85.     '''Return a list of TypelibSpec objects, one for each registered library.
  86. \t'''
  87.     key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, 'Typelib')
  88.     iids = EnumKeys(key)
  89.     results = []
  90.     for iid, crap in iids:
  91.         
  92.         try:
  93.             key2 = win32api.RegOpenKey(key, str(iid))
  94.         except win32api.error:
  95.             continue
  96.  
  97.         for version, tlbdesc in EnumKeys(key2):
  98.             major_minor = version.split('.', 1)
  99.             if len(major_minor) < 2:
  100.                 major_minor.append('0')
  101.             major = major_minor[0]
  102.             minor = major_minor[1]
  103.             key3 = win32api.RegOpenKey(key2, str(version))
  104.             
  105.             try:
  106.                 flags = int(win32api.RegQueryValue(key3, 'FLAGS'))
  107.             except (win32api.error, ValueError):
  108.                 flags = 0
  109.  
  110.             if flags & excludeFlags == 0:
  111.                 for lcid, crap in EnumKeys(key3):
  112.                     
  113.                     try:
  114.                         lcid = int(lcid)
  115.                     except ValueError:
  116.                         continue
  117.  
  118.                     
  119.                     try:
  120.                         key4 = win32api.RegOpenKey(key3, '%s\\win32' % (lcid,))
  121.                     except win32api.error:
  122.                         continue
  123.  
  124.                     
  125.                     try:
  126.                         (dll, typ) = win32api.RegQueryValueEx(key4, None)
  127.                         if typ == win32con.REG_EXPAND_SZ:
  128.                             dll = win32api.ExpandEnvironmentStrings(dll)
  129.                     except win32api.error:
  130.                         dll = None
  131.  
  132.                     spec = TypelibSpec(iid, lcid, major, minor, flags)
  133.                     spec.dll = dll
  134.                     spec.desc = tlbdesc
  135.                     spec.ver_desc = tlbdesc + ' (' + version + ')'
  136.                     results.append(spec)
  137.                 
  138.     
  139.     return results
  140.  
  141.  
  142. def FindTlbsWithDescription(desc):
  143.     '''Find all installed type libraries with the specified description
  144. \t'''
  145.     ret = []
  146.     items = EnumTlbs()
  147.     for item in items:
  148.         if item.desc == desc:
  149.             ret.append(item)
  150.             continue
  151.     return ret
  152.  
  153.  
  154. def SelectTlb(title = 'Select Library', excludeFlags = 0):
  155.     '''Display a list of all the type libraries, and select one.   Returns None if cancelled
  156. \t'''
  157.     import pywin.dialogs.list as pywin
  158.     items = EnumTlbs(excludeFlags)
  159.     for i in items:
  160.         i.major = int(i.major, 16)
  161.         i.minor = int(i.minor, 16)
  162.     
  163.     items.sort()
  164.     rc = pywin.dialogs.list.SelectFromLists(title, items, [
  165.         'Type Library'])
  166.     if rc is None:
  167.         return None
  168.     return None[rc]
  169.  
  170. if __name__ == '__main__':
  171.     print SelectTlb().__dict__
  172.