Skip to content

Commit b2ac158

Browse files
Merge f4f4b3a into 0316158
2 parents 0316158 + f4f4b3a commit b2ac158

11 files changed

Lines changed: 823 additions & 53 deletions

File tree

source/NVDAObjects/UIA/__init__.py

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Babbage B.V., Leonard de Ruijter, Bill Dengler
66

77
"""Support for UI Automation (UIA) controls."""
8-
8+
import typing
99
from ctypes import byref
1010
from ctypes.wintypes import POINT, RECT
1111
from comtypes import COMError
@@ -17,6 +17,7 @@
1717
import colors
1818
import languageHandler
1919
import UIAHandler
20+
import _UIACustomProps
2021
import globalVars
2122
import eventHandler
2223
import controlTypes
@@ -813,6 +814,9 @@ def updateSelection(self):
813814
updateCaret = updateSelection
814815

815816
class UIA(Window):
817+
_UIACustomProps = _UIACustomProps.CustomPropertiesCommon.get()
818+
819+
shouldAllowDuplicateUIAFocusEvent = False
816820

817821
def _get__coreCycleUIAPropertyCacheElementCache(self):
818822
"""
@@ -872,6 +876,19 @@ def findOverlayClasses(self,clsList):
872876
clsList.append(WpfTextView)
873877
elif UIAClassName=="NetUIDropdownAnchor":
874878
clsList.append(NetUIDropdownAnchor)
879+
elif self.windowClassName == "EXCEL6" and self.role == controlTypes.ROLE_PANE:
880+
from .excel import BadExcelFormulaEdit
881+
clsList.append(BadExcelFormulaEdit)
882+
elif self.windowClassName == "EXCEL7":
883+
if self.role in (controlTypes.ROLE_DATAITEM, controlTypes.ROLE_HEADERITEM):
884+
from .excel import ExcelCell
885+
clsList.append(ExcelCell)
886+
elif self.role == controlTypes.ROLE_DATAGRID:
887+
from .excel import ExcelWorksheet
888+
clsList.append(ExcelWorksheet)
889+
elif self.role == controlTypes.ROLE_EDITABLETEXT:
890+
from .excel import CellEdit
891+
clsList.append(CellEdit)
875892
elif self.TextInfo == UIATextInfo and (
876893
UIAClassName == '_WwG'
877894
or self.windowClassName == '_WwG'
@@ -1168,8 +1185,64 @@ def _get_UIASelectionItemPattern(self):
11681185
self.UIASelectionItemPattern=self._getUIAPattern(UIAHandler.UIA_SelectionItemPatternId,UIAHandler.IUIAutomationSelectionItemPattern)
11691186
return self.UIASelectionItemPattern
11701187

1188+
def _get_UIASelectionPattern(self):
1189+
self.UIASelectionPattern = self._getUIAPattern(
1190+
UIAHandler.UIA_SelectionPatternId,
1191+
UIAHandler.IUIAutomationSelectionPattern
1192+
)
1193+
return self.UIASelectionPattern
1194+
1195+
def _get_UIASelectionPattern2(self):
1196+
self.UIASelectionPattern2 = self._getUIAPattern(
1197+
UIAHandler.UIA_SelectionPattern2Id,
1198+
UIAHandler.IUIAutomationSelectionPattern2
1199+
)
1200+
return self.UIASelectionPattern2
1201+
1202+
def getSelectedItemsCount(self, maxItems=None):
1203+
p = self.UIASelectionPattern2
1204+
if p:
1205+
return p.currentItemCount
1206+
return 0
1207+
1208+
#: Typing information for auto-property: _get_selectionContainer
1209+
selectionContainer: "typing.Optional[UIA]"
1210+
1211+
def _get_selectionContainer(self) -> "typing.Optional[UIA]":
1212+
p = self.UIASelectionItemPattern
1213+
if not p:
1214+
return None
1215+
e = p.currentSelectionContainer
1216+
e = e.buildUpdatedCache(UIAHandler.handler.baseCacheRequest)
1217+
obj = UIA(UIAElement=e)
1218+
if obj.UIASelectionPattern2:
1219+
return obj
1220+
return None
1221+
1222+
#: typing for auto-property: UIAAnnotationObjects
1223+
UIAAnnotationObjects: typing.Dict[int, UIAHandler.IUIAutomationElement]
1224+
1225+
def _get_UIAAnnotationObjects(self) -> typing.Dict[int, UIAHandler.IUIAutomationElement]:
1226+
"""
1227+
Returns this UIAElement's annotation objects,
1228+
in a dict keyed by their annotation type ID.
1229+
"""
1230+
objsByTypeID = {}
1231+
objs = self._getUIACacheablePropertyValue(UIAHandler.UIA_AnnotationObjectsPropertyId)
1232+
if objs:
1233+
objs = objs.QueryInterface(UIAHandler.IUIAutomationElementArray)
1234+
for index in range(objs.length):
1235+
obj = objs.getElement(index)
1236+
typeID = obj.GetCurrentPropertyValue(UIAHandler.UIA_AnnotationAnnotationTypeIdPropertyId)
1237+
objsByTypeID[typeID] = obj
1238+
return objsByTypeID
1239+
11711240
def _get_UIATextPattern(self):
1172-
self.UIATextPattern=self._getUIAPattern(UIAHandler.UIA_TextPatternId,UIAHandler.IUIAutomationTextPattern,cache=True)
1241+
self.UIATextPattern = self._getUIAPattern(
1242+
UIAHandler.UIA_TextPatternId,
1243+
UIAHandler.IUIAutomationTextPattern,
1244+
cache=False
1245+
)
11731246
return self.UIATextPattern
11741247

11751248
def _get_UIATextEditPattern(self):
@@ -1247,7 +1320,10 @@ def _get_UIAAutomationId(self):
12471320
# #11445: due to timing errors, elements will be instantiated with no automation Id present.
12481321
return ""
12491322

1250-
def _get_name(self):
1323+
#: Typing info for auto property _get_name()
1324+
name: str
1325+
1326+
def _get_name(self) -> str:
12511327
try:
12521328
return self._getUIACacheablePropertyValue(UIAHandler.UIA_NamePropertyId)
12531329
except COMError:
@@ -1320,6 +1396,7 @@ def _get_keyboardShortcut(self):
13201396
UIAHandler.UIA_IsSelectionItemPatternAvailablePropertyId,
13211397
UIAHandler.UIA_IsEnabledPropertyId,
13221398
UIAHandler.UIA_IsOffscreenPropertyId,
1399+
UIAHandler.UIA_AnnotationTypesPropertyId,
13231400
}
13241401

13251402
def _get_states(self):
@@ -1385,6 +1462,10 @@ def _get_states(self):
13851462
states.add(controlTypes.STATE_CHECKABLE)
13861463
if s==UIAHandler.ToggleState_On:
13871464
states.add(controlTypes.STATE_CHECKED)
1465+
annotationTypes = self._getUIACacheablePropertyValue(UIAHandler.UIA_AnnotationTypesPropertyId)
1466+
if annotationTypes:
1467+
if UIAHandler.AnnotationType_Comment in annotationTypes:
1468+
states.add(controlTypes.STATE_HASCOMMENT)
13881469
return states
13891470

13901471
def _getReadOnlyState(self) -> bool:
@@ -1447,7 +1528,10 @@ def _get_previous(self):
14471528
return None
14481529
return self.correctAPIForRelation(UIA(UIAElement=previousElement))
14491530

1450-
def _get_next(self):
1531+
#: Typing information for auto-property: _get_next
1532+
next: "typing.Optional[UIA]"
1533+
1534+
def _get_next(self) -> "typing.Optional[UIA]":
14511535
try:
14521536
nextElement=UIAHandler.handler.baseTreeWalker.GetNextSiblingElementBuildCache(self.UIAElement,UIAHandler.handler.baseCacheRequest)
14531537
except COMError:
@@ -1784,7 +1868,7 @@ def _get_positionInfo(self):
17841868
info={}
17851869
itemIndex=0
17861870
try:
1787-
itemIndex=self._getUIACacheablePropertyValue(UIAHandler.handler.ItemIndex_PropertyId)
1871+
itemIndex = self._getUIACacheablePropertyValue(self._UIACustomProps.itemIndex.id)
17881872
except COMError:
17891873
pass
17901874
if itemIndex>0:
@@ -1796,7 +1880,7 @@ def _get_positionInfo(self):
17961880
e=None
17971881
if e:
17981882
try:
1799-
itemCount=e.getCurrentPropertyValue(UIAHandler.handler.ItemCount_PropertyId)
1883+
itemCount = e.getCurrentPropertyValue(self._UIACustomProps.itemCount.id)
18001884
except COMError:
18011885
itemCount=0
18021886
if itemCount>0:

0 commit comments

Comments
 (0)