55
66"""Base classes with common support for browsers exposing IAccessible2.
77"""
8- import typing
8+
99from typing import (
10- Iterable ,
10+ Generator ,
11+ Optional ,
12+ Tuple ,
1113)
1214from ctypes import c_short
1315from comtypes import COMError , BSTR
1416
1517import oleacc
1618from annotation import (
19+ _AnnotationRolesT ,
1720 AnnotationTarget ,
1821 AnnotationOrigin ,
1922)
@@ -57,21 +60,24 @@ def __bool__(self) -> bool:
5760 )
5861
5962 @property
60- def targets (self ) -> Iterable [AnnotationTarget ]:
63+ def targets (self ) -> Tuple [AnnotationTarget ]:
6164 if not bool (self ):
6265 # optimisation that avoids having to fetch details relations which may be a more costly procedure.
6366 if config .conf ["debugLog" ]["annotations" ]:
6467 log .debug ("no annotations available" )
6568 return
6669
67- ia2WebAnnotationTargetsGen = (
70+ return tuple (
6871 IA2WebAnnotationTarget (rel )
6972 for rel in self ._originObj .detailsRelations
7073 )
71- yield from ia2WebAnnotationTargetsGen
7274
7375 @property
74- def roles (self ) -> Iterable [controlTypes .Role ]:
76+ def roles (self ) -> _AnnotationRolesT :
77+ return tuple (self ._rolesGenerator )
78+
79+ @property
80+ def _rolesGenerator (self ) -> Generator [Optional [controlTypes .Role ], None , None ]:
7581 """
7682 Since Chromium exposes the roles via the "details-roles" IA2Attributes, an optimisation can be used
7783 to return them.
@@ -95,11 +101,6 @@ def roles(self) -> Iterable[controlTypes.Role]:
95101 log .debug (f"detailsRole: { repr (detailsRole )} " )
96102 yield detailsRole
97103
98- @property
99- def summaries (self ) -> Iterable [str ]:
100- for target in self .targets :
101- yield target .summary
102-
103104
104105class Ia2Web (IAccessible ):
105106 IAccessibleTableUsesTableCellIndexAttrib = True
@@ -129,7 +130,7 @@ def _get_positionInfo(self):
129130 return info
130131
131132 def _get_descriptionFrom (self ) -> controlTypes .DescriptionFrom :
132- ia2attrDescriptionFrom : typing . Optional [str ] = self .IA2Attributes .get ("description-from" )
133+ ia2attrDescriptionFrom : Optional [str ] = self .IA2Attributes .get ("description-from" )
133134 try :
134135 return controlTypes .DescriptionFrom (ia2attrDescriptionFrom )
135136 except ValueError :
@@ -144,14 +145,13 @@ def _get_annotations(self) -> "AnnotationOrigin":
144145 annotationOrigin = IA2WebAnnotation (self )
145146 return annotationOrigin
146147
147- def _get_detailsSummary (self ) -> typing . Optional [str ]:
148+ def _get_detailsSummary (self ) -> Optional [str ]:
148149 log .warning (
149150 "NVDAObject.detailsSummary is deprecated. Use NVDAObject.annotations instead." ,
150151 stack_info = True ,
151152 )
152- for summary in self .annotations .summaries :
153- # just take the first for now.
154- return summary
153+ # just take the first for now.
154+ return self .annotations .targets [0 ].summary
155155
156156 @property
157157 def hasDetails (self ) -> bool :
@@ -161,14 +161,13 @@ def hasDetails(self) -> bool:
161161 )
162162 return bool (self .annotations )
163163
164- def _get_detailsRole (self ) -> typing . Optional [controlTypes .Role ]:
164+ def _get_detailsRole (self ) -> Optional [controlTypes .Role ]:
165165 log .warning (
166166 "NVDAObject.detailsRole is deprecated. Use NVDAObject.annotations instead." ,
167167 stack_info = True ,
168168 )
169- for role in self .annotations .roles :
170- # just take the first for now.
171- return role
169+ # just take the first for now.
170+ return self .annotations .roles [0 ]
172171
173172 def _get_isCurrent (self ) -> controlTypes .IsCurrent :
174173 ia2attrCurrent : str = self .IA2Attributes .get ("current" , "false" )
0 commit comments