How to use the comtypes.COMError function in comtypes

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 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 nvaccess / nvda / source / NVDAObjects / window / edit.py View on Github external
def makeTextInfo(self,position):
		if self.TextInfo is not ITextDocumentTextInfo:
			return super(RichEdit,self).makeTextInfo(position)
		# #4090: Sometimes ITextDocument support can fail (security restrictions in Outlook 2010)
		# We then fall back to normal Edit support.
		try:
			return self.TextInfo(self,position)
		except COMError:
			log.debugWarning("Could not instanciate ITextDocumentTextInfo",exc_info=True)
			self.TextInfo=EditTextInfo
			return self.TextInfo(self,position)
github F1ashhimself / UISoup / uisoup / win_soup / element.py View on Github external
def _get_child_count_safely(self, i_accessible):
        """
        Safely gets child count.

        :param i_accessible: instance of i_accessible.
        :rtype: int
        :return: object child count
        """
        try:
            return i_accessible.accChildCount
        except Exception as ex:
            if isinstance(ex, comtypes.COMError) and getattr(ex, 'hresult') \
                    in (CO_E_OBJNOTCONNECTED,):
                return 0
github nvaccess / nvda / source / mathPlayer.py View on Github external
def script_navigate(self, gesture):
		modNames = gesture.modifierNames
		try:
			text = _mpNavigation.DoNavigateKeyPress(gesture.vkCode,
				"shift" in modNames, "control" in modNames, "alt" in modNames, False)
		except COMError:
			return
		speech.speakText(_processMpSpeech(text),
			symbolLevel=characterProcessing.SYMLVL_NONE)
github nvaccess / nvda / source / UIABrowseMode.py View on Github external
def __contains__(self,obj):
		if not isinstance(obj,UIA):
			return False
		# Ensure that this object is a descendant of the document or is the document itself. 
		runtimeID=VARIANT()
		self.rootNVDAObject.UIAElement._IUIAutomationElement__com_GetCurrentPropertyValue(UIAHandler.UIA_RuntimeIdPropertyId,byref(runtimeID))
		UIACondition=UIAHandler.handler.clientObject.createPropertyCondition(UIAHandler.UIA_RuntimeIdPropertyId,runtimeID)
		UIAWalker=UIAHandler.handler.clientObject.createTreeWalker(UIACondition)
		try:
			docUIAElement=UIAWalker.normalizeElement(obj.UIAElement)
		except COMError:
			docUIAElement=None
		if not docUIAElement:
			return False
		# Ensure that this object also can be reached by the document's text pattern.
		try:
			self.rootNVDAObject.makeTextInfo(obj)
		except LookupError:
			return False
		return True
github enthought / comtypes / comtypes / client / lazybind.py View on Github external
def __bind(self, name, invkind):
        """Bind (name, invkind) and return a FuncDesc instance or
        None.  Results (even unsuccessful ones) are cached."""
        # We could cache the info in the class instead of the
        # instance, but we would need an additional key for that:
        # self._iid
        try:
            return self._tdesc[(name, invkind)]
        except KeyError:
            try:
                descr = self._tcomp.Bind(name, invkind)[1]
            except comtypes.COMError:
                info = None
            else:
                # Using a separate instance to store interesting
                # attributes of descr avoids that the typecomp instance is
                # kept alive...
                info = FuncDesc(memid=descr.memid,
                                invkind=descr.invkind,
                                cParams=descr.cParams,
                                funckind=descr.funckind)
            self._tdesc[(name, invkind)] = info
            return info
github enthought / comtypes / comtypes / automation.py View on Github external
dp.rgdispidNamedArgs = pointer(DISPID(DISPID_PROPERTYPUT))
        else:
            array = (VARIANT * len(args))()

            for i, a in enumerate(args[::-1]):
                array[i].value = a

            dp = DISPPARAMS()
            dp.cArgs = len(args)
            dp.cNamedArgs = 0
            dp.rgvarg = array

        try:
            self.__com_Invoke(dispid, riid_null, _lcid, _invkind, byref(dp),
                              byref(result), byref(excepinfo), byref(argerr))
        except COMError, err:
            (hresult, text, details) = err.args
            if hresult == DISP_E_EXCEPTION:
                details = (excepinfo.bstrDescription, excepinfo.bstrSource,
                           excepinfo.bstrHelpFile, excepinfo.dwHelpContext,
                           excepinfo.scode)
                raise COMError(hresult, text, details)
            elif hresult == DISP_E_PARAMNOTFOUND:
                # MSDN says: You get the error DISP_E_PARAMNOTFOUND
                # when you try to set a property and you have not
                # initialized the cNamedArgs and rgdispidNamedArgs
                # elements of your DISPPARAMS structure.
                #
                # So, this looks like a bug.
                raise COMError(hresult, text, argerr.value)
            elif hresult == DISP_E_TYPEMISMATCH:
                # MSDN: One or more of the arguments could not be
github nvaccess / nvda / source / appModules / itunes.py View on Github external
def _get_next(self):
		next=super(ITunesItem,self).next
		if next:
			return next
		try:
			parentChildCount=self.IAccessibleObject.accChildCount
		except COMError:
			parentChildCount=0
		if self.IAccessibleChildID>0 and self.IAccessibleChildID
github enthought / comtypes / comtypes / client / __init__.py View on Github external
if tinfo.GetImplTypeFlags(index) == 1:
                break
        else:
            if ta.cImplTypes != 1:
                # Hm, should we use dynamic now?
                raise TypeError("No default interface found")
            # Only one interface implemented, use that (even if
            # not marked as default).
            index = 0
        href = tinfo.GetRefTypeOfImplType(index)
        tinfo = tinfo.GetRefTypeInfo(href)
    except comtypes.COMError:
        logger.debug("Does NOT implement IProvideClassInfo/IProvideClassInfo2")
        try:
            pdisp = punk.QueryInterface(comtypes.automation.IDispatch)
        except comtypes.COMError:
            logger.debug("No Dispatch interface: %s", punk)
            return punk
        try:
            tinfo = pdisp.GetTypeInfo(0)
        except comtypes.COMError:
            pdisp = comtypes.client.dynamic.Dispatch(pdisp)
            logger.debug("IDispatch.GetTypeInfo(0) failed: %s" % pdisp)
            return pdisp
    typeattr = tinfo.GetTypeAttr()
    logger.debug("Default interface is %s", typeattr.guid)
    try:
        punk.QueryInterface(comtypes.IUnknown, typeattr.guid)
    except comtypes.COMError:
        logger.debug("Does not implement default interface, returning dynamic object")
        return comtypes.client.dynamic.Dispatch(punk)
github reclosedev / pyautocad / pyautocad / selset / __init__.py View on Github external
def _ssget(selection_sets, filter_type, filter_data,
           selection=AutoCAD.acSelectionSetAll, name="SS_1__"):
    try:
        selection_sets.Item(name).Delete()
    except Exception:
        pass
    sset = selection_sets.Add(name)
    try:
        sset.Select(
            selection,
            FilterType=array.array('h', filter_type),
            FilterData=filter_data,
        )
    except comtypes.COMError as e:
        print e.details[0]
        raise
    return sset