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

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