home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import win32api
- import win32con
- import string
- import pythoncom
-
- class TypelibSpec:
-
- def __init__(self, clsid, lcid, major, minor, flags = 0):
- self.clsid = str(clsid)
- self.lcid = int(lcid)
- self.major = major
- self.minor = minor
- self.dll = None
- self.desc = None
- self.ver_desc = None
- self.flags = flags
-
-
- def __getitem__(self, item):
- if item == 0:
- return self.ver_desc
- raise IndexError, 'Cant index me!'
-
-
- def __cmp__(self, other):
- if not self.ver_desc:
- pass
- if not other.ver_desc:
- pass
- rc = cmp(string.lower(''), string.lower(''))
- if rc == 0:
- rc = cmp(string.lower(self.desc), string.lower(other.desc))
-
- if rc == 0:
- rc = cmp(self.major, other.major)
-
- if rc == 0:
- rc = cmp(self.major, other.minor)
-
- return rc
-
-
- def Resolve(self):
- if self.dll is None:
- return 0
- tlb = pythoncom.LoadTypeLib(self.dll)
- self.FromTypelib(tlb, None)
- return 1
-
-
- def FromTypelib(self, typelib, dllName = None):
- la = typelib.GetLibAttr()
- self.clsid = str(la[0])
- self.lcid = la[1]
- self.major = la[3]
- self.minor = la[4]
- if dllName:
- self.dll = dllName
-
-
-
-
- def EnumKeys(root):
- index = 0
- ret = []
- while None:
-
- try:
- item = win32api.RegEnumKey(root, index)
- except win32api.error:
- break
-
-
- try:
- val = win32api.RegQueryValue(root, item)
- except win32api.error:
- val = ''
-
- index = index + 1
- continue
- return ret
-
- FLAG_RESTRICTED = 1
- FLAG_CONTROL = 2
- FLAG_HIDDEN = 4
-
- def EnumTlbs(excludeFlags = 0):
- key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, 'Typelib')
- iids = EnumKeys(key)
- results = []
- for iid, crap in iids:
-
- try:
- key2 = win32api.RegOpenKey(key, str(iid))
- except win32api.error:
- continue
-
- for version, tlbdesc in EnumKeys(key2):
- major_minor = string.split(version, '.', 1)
- if len(major_minor) < 2:
- major_minor.append('0')
-
- major = major_minor[0]
- minor = major_minor[1]
- key3 = win32api.RegOpenKey(key2, str(version))
-
- try:
- flags = int(win32api.RegQueryValue(key3, 'FLAGS'))
- except (win32api.error, ValueError):
- flags = 0
-
- if flags & excludeFlags == 0:
- for lcid, crap in EnumKeys(key3):
-
- try:
- lcid = int(lcid)
- except ValueError:
- continue
-
-
- try:
- key4 = win32api.RegOpenKey(key3, '%s\\win32' % (lcid,))
- except win32api.error:
- continue
-
-
- try:
- (dll, typ) = win32api.RegQueryValueEx(key4, None)
- if typ == win32con.REG_EXPAND_SZ:
- dll = win32api.ExpandEnvironmentStrings(dll)
- except win32api.error:
- dll = None
-
- spec = TypelibSpec(iid, lcid, major, minor, flags)
- spec.dll = dll
- spec.desc = tlbdesc
- spec.ver_desc = tlbdesc + ' (' + version + ')'
- results.append(spec)
-
-
-
- return results
-
-
- def FindTlbsWithDescription(desc):
- ret = []
- items = EnumTlbs()
- for item in items:
- if item.desc == desc:
- ret.append(item)
- continue
-
- return ret
-
-
- def SelectTlb(title = 'Select Library', excludeFlags = 0):
- import pywin.dialogs.list as pywin
- items = EnumTlbs(excludeFlags)
- for i in items:
- i.major = int(i.major, 16)
- i.minor = int(i.minor, 16)
-
- items.sort()
- rc = pywin.dialogs.list.SelectFromLists(title, items, [
- 'Type Library'])
- if rc is None:
- return None
- return items[rc]
-
- if __name__ == '__main__':
- print SelectTlb().__dict__
-
-