Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _is_object(obj):
"""This function determines if the argument is a COM object. It
is used in several places to determine whether propputref or
propput setters have to be used."""
from comtypes.automation import VARIANT
# A COM pointer is an 'Object'
if isinstance(obj, POINTER(IUnknown)):
return True
# A COM pointer in a VARIANT is an 'Object', too
elif isinstance(obj, VARIANT) and isinstance(obj.value, POINTER(IUnknown)):
return True
# It may be a dynamic dispatch object.
return hasattr(obj, "_comobj")
def accSelection(self):
'''Get Element Selection Status'''
objChildren = comtypes.automation.VARIANT()
self.IAccessible._IAccessible__com__get_accSelection(ctypes.byref(objChildren))
return objChildren.value
def accDescription(self):
'''Get Element Description'''
objChildId = comtypes.automation.VARIANT()
objChildId.vt = comtypes.automation.VT_I4
objChildId.value = self.iObjectId
objDescription = comtypes.automation.BSTR()
self.IAccessible._IAccessible__com__get_accDescription(objChildId, ctypes.byref(objDescription))
return objDescription.value
def accState(self):
'''Get Element State'''
objChildId = comtypes.automation.VARIANT()
objChildId.vt = comtypes.automation.VT_I4
objChildId.value = self.iObjectId
objState = comtypes.automation.VARIANT()
self.IAccessible._IAccessible__com__get_accState(objChildId, ctypes.byref(objState))
return objState.value
def _acc_state(self):
obj_child_id = comtypes.automation.VARIANT()
obj_child_id.vt = comtypes.automation.VT_I4
obj_child_id.value = self._i_object_id
obj_state = comtypes.automation.VARIANT()
self._i_accessible._IAccessible__com__get_accState(
obj_child_id, ctypes.byref(obj_state))
return obj_state.value
def accValue(self, objValue=None):
'''Get Element Value'''
objChildId = comtypes.automation.VARIANT()
objChildId.vt = comtypes.automation.VT_I4
objChildId.value = self.iObjectId
objBSTRValue = comtypes.automation.BSTR()
if objValue is None:
self.IAccessible._IAccessible__com__get_accValue(objChildId, ctypes.byref(objBSTRValue))
return objBSTRValue.value
else:
objBSTRValue.value = objValue
self.IAccessible._IAccessible__com__set_accValue(objChildId, objValue)
return objBSTRValue.value
def _role(self):
"""
Property for element role.
"""
obj_child_id = comtypes.automation.VARIANT()
obj_child_id.vt = comtypes.automation.VT_I4
obj_child_id.value = self._i_object_id
obj_role = comtypes.automation.VARIANT()
obj_role.vt = comtypes.automation.VT_BSTR
self._i_accessible._IAccessible__com__get_accRole(obj_child_id,
obj_role)
return obj_role.value
def get_object_by_coordinates(self, x, y):
obj_point = ctypes.wintypes.POINT()
obj_point.x = x
obj_point.y = y
i_accessible = ctypes.POINTER(comtypes.gen.Accessibility.IAccessible)()
obj_child_id = comtypes.automation.VARIANT()
ctypes.oledll.oleacc.AccessibleObjectFromPoint(
obj_point,
ctypes.byref(i_accessible),
ctypes.byref(obj_child_id))
return WinElement(i_accessible, obj_child_id.value or 0)