示例#1
0
def dump_signatures():
    tlbs = selecttlb.EnumTlbs()
    tlbs = {tlb.clsid: tlb for tlb in tlbs}

    tlbSpec = tlbs.get(module_clsid)

    if tlbSpec is None:
        raise LookupError('KHOpenAPI Module not found')

    if tlbSpec.dll is None:
        tlb = pythoncom.LoadRegTypeLib(tlbSpec.clsid, int(tlbSpec.major, 16),
                                       int(tlbSpec.minor, 16), tlbSpec.lcid)
    else:
        tlb = pythoncom.LoadTypeLib(tlbSpec.dll)

    gen = genpy.Generator(tlb, tlbSpec.dll, None, bBuildHidden=1)
    oleItems, _enumItems, _recordItems, _vtableItems = gen.BuildOleItemsFromType(
    )

    items = [l for l in oleItems.values() if l is not None]
    items.sort()

    iteritems = iter(items)

    dispatch = next(iteritems, None)
    event = next(iteritems, None)

    if dispatch is None:
        raise LookupError('KHOpenAPI Dispatch not found')

    if event is None:
        raise LookupError('KHOpenAPI Event not found')

    dispatch_funcs = [
        (name, entry) for name, entry in dispatch.mapFuncs.items() if not any([
            entry.desc[9] & pythoncom.FUNCFLAG_FRESTRICTED
            and entry.desc[0] != pythoncom.DISPID_NEWENUM, entry.desc[3] !=
            pythoncom.FUNC_DISPATCH, entry.desc[0] == pythoncom.DISPID_NEWENUM
        ])
    ]

    dispatch_signatures_by_name = OrderedDict()  # pylint: disable=redefined-outer-name

    for func_name, entry in dispatch_funcs:
        signature = signature_from_entry(entry)
        dispatch_signatures_by_name[func_name] = signature

    event_funcs = event.mapFuncs.items()

    event_signatures_by_name = OrderedDict()  # pylint: disable=redefined-outer-name

    for func_name, entry in event_funcs:
        signature = signature_from_entry(entry)
        event_signatures_by_name[func_name] = signature

    with open(dispatch_signatures_by_name_filepath, 'wb') as f:
        pickle.dump(dispatch_signatures_by_name, f)

    with open(event_signatures_by_name_filepath, 'wb') as f:
        pickle.dump(event_signatures_by_name, f)
示例#2
0
def TestBuildAll(verbose=1):
    num = 0
    tlbInfos = selecttlb.EnumTlbs()
    for info in tlbInfos:
        if verbose:
            print("%s (%s)" % (info.desc, info.dll))
        try:
            makepy.GenerateFromTypeLibSpec(info)
            #          sys.stderr.write("Attr typeflags for coclass referenced object %s=%d (%d), typekind=%d\n" % (name, refAttr.wTypeFlags, refAttr.wTypeFlags & pythoncom.TYPEFLAG_FDUAL,refAttr.typekind))
            num += 1
        except pythoncom.com_error as details:
            # Ignore these 2 errors, as the are very common and can obscure
            # useful warnings.
            if details.hresult not in [
                    winerror.TYPE_E_CANTLOADLIBRARY,
                    winerror.TYPE_E_LIBNOTREGISTERED,
            ]:
                print("** COM error on", info.desc)
                print(details)
        except KeyboardInterrupt:
            print("Interrupted!")
            raise KeyboardInterrupt
        except:
            print("Failed:", info.desc)
            traceback.print_exc()
        if makepy.bForDemandDefault:
            # This only builds enums etc by default - build each
            # interface manually
            tinfo = (info.clsid, info.lcid, info.major, info.minor)
            mod = gencache.EnsureModule(info.clsid, info.lcid, info.major,
                                        info.minor)
            for name in mod.NamesToIIDMap.keys():
                makepy.GenerateChildFromTypeLibSpec(name, tinfo)
    return num
示例#3
0
 def OnMakepydialogInitDialog(self, event):
     '''Initialisation of the dialog starts up a
     process of loading the type library definitions.'''
     wx.BeginBusyCursor()
     try:
         self.libraryList = libraryList = selecttlb.EnumTlbs()
         libraryList.sort()
         for index in range(len(libraryList)):
             librarySpecification = libraryList[index]
             self.typeLibraryList.InsertStringItem(
                 index, librarySpecification.desc)
     finally:
         wx.EndBusyCursor()
示例#4
0
def TestBuildAll(verbose = 1):
    num = 0
    tlbInfos = selecttlb.EnumTlbs()
    for info in tlbInfos:
        if verbose:
            print "%s (%s)" % (info.desc, info.dll)
        try:
            makepy.GenerateFromTypeLibSpec(info)
#          sys.stderr.write("Attr typeflags for coclass referenced object %s=%d (%d), typekind=%d\n" % (name, refAttr.wTypeFlags, refAttr.wTypeFlags & pythoncom.TYPEFLAG_FDUAL,refAttr.typekind))
            num += 1
        except pythoncom.com_error, details:
            # Ignore these 2 errors, as the are very common and can obscure
            # useful warnings.
            if details[0] not in [winerror.TYPE_E_CANTLOADLIBRARY,
                              winerror.TYPE_E_LIBNOTREGISTERED]:
                print "** COM error on", info.desc
                print details
        except KeyboardInterrupt:
            print "Interrupted!"
            raise KeyboardInterrupt
示例#5
0
def BuildOleItems(clsid):
    tlbs = selecttlb.EnumTlbs()
    tlbs = {tlb.clsid: tlb for tlb in tlbs}

    tlbSpec = tlbs.get(clsid)

    if tlbSpec is None:
        return {}
        raise LookupError('KHOpenAPI Module not found')

    if tlbSpec.dll is None:
        tlb = pythoncom.LoadRegTypeLib(tlbSpec.clsid, int(tlbSpec.major, 16), int(tlbSpec.minor, 16), tlbSpec.lcid)
    else:
        tlb = pythoncom.LoadTypeLib(tlbSpec.dll)

    gen = genpy.Generator(tlb, tlbSpec.dll, None, bBuildHidden=1)
    oleItems, _enumItems, _recordItems, _vtableItems = gen.BuildOleItemsFromType()

    oleItems = {str(clsId): oleItem for clsId, oleItem in oleItems.items()}

    return oleItems
import os
from win32com.client import selecttlb
from win32com.client import gencache

info = [
    (('TEM Scripting', 'Tecnai Scripting'), 'TEM Scripting'),
    (('TOMMoniker 1.0 Type Library', ), 'TOM Moniker'),
    (('Low Dose Server Library', ), 'Tecnai Low Dose Kit'),
    (('adaExp Library', ), 'Tecnai Exposure Adaptor'),
    (('TecnaiCCD 1.0 Type Library', ), 'Gatan CCD Camera'),
    (('CAMC4 1.0 Type Library', ), 'Tietz CCD Camera'),
    (('ES Vision 3.1 Type Library', 'ES Vision 3.0 Type Library'),
     'TIA CCD Camera'),
]
items = selecttlb.EnumTlbs()


def getTlbFromDesc(desc):
    for item in items:
        if item.desc == desc:
            return item
    return None


def makeFile(descs):
    typelibInfo = None
    for desc in descs:
        typelibInfo = getTlbFromDesc(desc)
        if typelibInfo is not None:
            print '\nFound: ', desc
            break