How to use comtypes - 10 common examples

To help you get started, we’ve selected a few comtypes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github toymachine / venster / test / test_dragdrop.py View on Github external
def __init__(self, *args, **kwargs):
        tree.Tree.__init__(self, *args, **kwargs)
        COMObject.__init__(self)
        
        RegisterDragDrop(self.handle, byref(self._com_pointers_[0][1]))
        
        self.iml = comctl.ImageList(16, 16, ILC_COLOR32 | ILC_MASK, 0, 32)
        self.iml.AddIconsFromModule("shell32.dll", 16, 16, LR_LOADMAP3DCOLORS)
        self.iml.SetBkColor(gdi.CLR_NONE)
        self.SetImageList(self.iml)

        self.SetRedraw(0)
        item = comctl.TVITEMEX()
        item.text = "A root"
        item.image = 17
        item.selectedImage = 17
        item.children = 1
        hRoot = self.InsertItem(comctl.TVI_ROOT, comctl.TVI_ROOT, item)
        for i in range(100):
github toymachine / venster / test / test_dragdrop.py View on Github external
## IDropSource:
    def GiveFeedback(self, this, dwEffect):
        #print "giveFeedback", dwEffect
        return DRAGDROP_S_USEDEFAULTCURSORS

    def QueryContinueDrag(self, this, fEscapePressed, grfKeyState):
        #print "qcd", fEscapePressed, grfKeyState
        if fEscapePressed:
            return DRAGDROP_S_CANCEL
        elif not (grfKeyState & MK_LBUTTON):
            return DRAGDROP_S_DROP
        else:
            return S_OK

        
class Tree(tree.Tree, COMObject):
    _com_interfaces_ = [IDropTarget]

    _factory = Factory()
    
    def __init__(self, *args, **kwargs):
        tree.Tree.__init__(self, *args, **kwargs)
        COMObject.__init__(self)
        
        RegisterDragDrop(self.handle, byref(self._com_pointers_[0][1]))
        
        self.iml = comctl.ImageList(16, 16, ILC_COLOR32 | ILC_MASK, 0, 32)
        self.iml.AddIconsFromModule("shell32.dll", 16, 16, LR_LOADMAP3DCOLORS)
        self.iml.SetBkColor(gdi.CLR_NONE)
        self.SetImageList(self.iml)

        self.SetRedraw(0)
github toymachine / venster / test / test_dragdrop.py View on Github external
item.image = 17
        item.selectedImage = 17
        item.children = 1
        hRoot = self.InsertItem(comctl.TVI_ROOT, comctl.TVI_ROOT, item)
        for i in range(100):
            item.mask = 0
            item.text = "A child %d" % i
            item.image = 3
            item.selectedImage = 4            
            hChild = self.InsertItem(hRoot, comctl.TVI_LAST, item)
        self.SetRedraw(1)

    def dispose(self):
        RevokeDragDrop(self.handle)

class List(list.List, COMObject):
    _com_interfaces_ = [IDropTarget]
    _factory = Factory()
    
    def __init__(self, *args, **kwargs):
        list.List.__init__(self, *args, **kwargs)
        COMObject.__init__(self)

        RegisterDragDrop(self.handle, byref(self._com_pointers_[0][1]))

        self.InsertColumns([("blaat", 100), ("col2", 150)])
        self.SetRedraw(0)
        for i in range(100):
            self.InsertRow(i, ["blaat %d" % i, "blaat col2 %d" % i])
        self.SetRedraw(1)

    def dispose(self):
github ipaleka / arrangeit / tests / unit / test_windows_vdi.py View on Github external
def test_windows_vdi_IObjectArray_method_GetAt(self):
        method = (
            ctypes.HRESULT,
            "GetAt",
            (
                ctypes.wintypes.UINT,
                ctypes.POINTER(GUID),
                ctypes.POINTER(ctypes.wintypes.LPVOID),
            ),
            ((1, "uiIndex"), (1, "riid"), (1, "ppv")),
            ("Method GetAt",),
            "Method GetAt",
        )
        assert method == vdi.IObjectArray._methods_[1]
github orf / wordinserter / wordinserter / cli.py View on Github external
', '.join(SAVE_FORMATS.keys())
            ), file=sys.stderr)
            exit(1)

        if save_as.exists():
            print('Error: Path {0} already exists. Not overwriting'.format(save_as), file=sys.stderr)
            exit(1)

    with Timer(factor=1000) as t:
        parsed = parse(text, stylesheets=css)

    print('Parsed in {0:f} ms'.format(t.elapsed))

    with Timer(factor=1000) as t:
        try:
            word = CreateObject("Word.Application")
        except AttributeError as e:
            gen_dir = inspect.getsourcefile(gen)

            print('****** There was an error opening word ******')
            print('This is a transient error that sometimes happens.')
            print('Remove all files (except __init__.py) from here:')
            print(os.path.dirname(gen_dir))
            print('Then retry the program')
            print('*********************************************')
            raise e
        doc = word.Documents.Add()

    print('Opened word in {0:f} ms'.format(t.elapsed))

    word.Visible = not arguments['--hidden']
github daid / LegacyCura / Cura / gui / util / taskbar.py View on Github external
"""
Api for taskbar. Only for windows 7 or higher (filling up the icon while its progressing).
"""
__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"

try:
	import comtypes.client as cc
	cc.GetModule('taskbarlib.tlb')
	import comtypes.gen.TaskbarLib as tbl

	ITaskbarList3 = cc.CreateObject("{56FDF344-FD6D-11d0-958A-006097C9A090}", interface=tbl.ITaskbarList3)
	ITaskbarList3.HrInit()

	#Stops displaying progress and returns the button to its normal state. Call this method with this flag to dismiss the progress bar when the operation is complete or canceled.
	TBPF_NOPROGRESS = 0x00000000
	#The progress indicator does not grow in size, but cycles repeatedly along the length of the taskbar button. This indicates activity without specifying what proportion of the progress is complete. Progress is taking place, but there is no prediction as to how long the operation will take.
	TBPF_INDETERMINATE = 0x00000001
	#The progress indicator grows in size from left to right in proportion to the estimated amount of the operation completed. This is a determinate progress indicator; a prediction is being made as to the duration of the operation.
	TBPF_NORMAL = 0x00000002
	#The progress indicator turns red to show that an error has occurred in one of the windows that is broadcasting progress. This is a determinate state. If the progress indicator is in the indeterminate state, it switches to a red determinate display of a generic percentage not indicative of actual progress.
	TBPF_ERROR = 0x00000004
	#The progress indicator turns yellow to show that progress is currently stopped in one of the windows but can be resumed by the user. No error condition exists and nothing is preventing the progress from continuing. This is a determinate state. If the progress indicator is in the indeterminate state, it switches to a yellow determinate display of a generic percentage not indicative of actual progress.
	TBPF_PAUSED = 0x00000008
except:
	#The taskbar API is only available for Windows7, on lower windows versions, linux or Mac it will cause an exception. Ignore the exception and don't use the API
	ITaskbarList3 = None
github kiraxie / liqueur / liqueur / util.py View on Github external
def install(self):
        with ZipFile(self._download_file, 'r') as archive:
            for fname in archive.namelist():
                name_parts = fname.split('/')
                if name_parts[-2] == 'x64' and name_parts[-1].endswith('.dll'):
                    target_path = str(self._package_work_dir) + r'\\' + name_parts[-1]
                    with archive.open(fname, 'r') as cmpf, open(target_path, 'wb') as extf:
                        extf.write(cmpf.read())
            self.__dll_file = Path(self._package_work_dir.as_posix() + '/SKCOM.dll')

        # special case: if the path object "as_posix" method will return "/",
        #               but in powershell just can use "\",so using
        #               "expanduser" method instead of "as_posix" method
        if not self._powershell_exec('regsvr32', [self.__dll_file.expanduser()], True):
            raise WindowsError('Install Capital API failure!\n' + self.stderr)
        comtypes.client.GetModule(self.__dll_file)
        self._get_curr_ver()
github nvaccess / nvda / source / NVDAObjects / IAccessible / mozilla.py View on Github external
def getGeckoVersion(obj):
	appMod = obj.appModule
	try:
		return appMod._geckoVersion
	except AttributeError:
		pass
	try:
		full = obj.IAccessibleObject.QueryInterface(IServiceProvider).QueryService(IAccessibleHandler.IAccessibleApplication._iid_, IAccessibleHandler.IAccessibleApplication).toolkitVersion
	except COMError:
		return None
	try:
		major = int(full.split(".", 1)[0])
	except ValueError:
		major = None
	ver = appMod._geckoVersion = GeckoVersion(full, major)
	return ver
github kshahar / pylaunchy / scripts / pyexplorey.py View on Github external
def init(self):
		GetModule("shdocvw.dll")
		SHDocVw = comtypes.gen.SHDocVw
		self.shellWindows = CreateObject(SHDocVw.ShellWindows)
		self.__listOpenExplorerDirectories()
github orf / wordinserter / wordinserter / cli.py View on Github external
exit(1)

        if save_as.exists():
            print('Error: Path {0} already exists. Not overwriting'.format(save_as), file=sys.stderr)
            exit(1)

    with Timer(factor=1000) as t:
        parsed = parse(text, stylesheets=css)

    print('Parsed in {0:f} ms'.format(t.elapsed))

    with Timer(factor=1000) as t:
        try:
            word = CreateObject("Word.Application")
        except AttributeError as e:
            gen_dir = inspect.getsourcefile(gen)

            print('****** There was an error opening word ******')
            print('This is a transient error that sometimes happens.')
            print('Remove all files (except __init__.py) from here:')
            print(os.path.dirname(gen_dir))
            print('Then retry the program')
            print('*********************************************')
            raise e
        doc = word.Documents.Add()

    print('Opened word in {0:f} ms'.format(t.elapsed))

    word.Visible = not arguments['--hidden']

    from comtypes.gen import Word as constants