-
-
Notifications
You must be signed in to change notification settings - Fork 766
Expand file tree
/
Copy path__init__.py
More file actions
797 lines (711 loc) · 25.4 KB
/
__init__.py
File metadata and controls
797 lines (711 loc) · 25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2006-2026 NV Access Limited, Leonard de Ruijter, Joseph Lee, Renaud Paquay, pvagner, hwf1324
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
import ctypes
import re
from typing import (
Any,
)
import eventHandler
import keyLabels
import JABHandler
import controlTypes
import textUtils
from controlTypes import TextPosition
from .. import NVDAObject, InvalidNVDAObject
from ..window import Window
from ..behaviors import ProgressBar, EditableTextWithoutAutoSelectDetection, Dialog
import textInfos.offsets
from logHandler import log
from locationHelper import RectLTWH
JABRolesToNVDARoles: dict[str, controlTypes.Role] = {
"alert": controlTypes.Role.DIALOG,
"column header": controlTypes.Role.TABLECOLUMNHEADER,
"canvas": controlTypes.Role.CANVAS,
"combo box": controlTypes.Role.COMBOBOX,
"desktop icon": controlTypes.Role.DESKTOPICON,
"internal frame": controlTypes.Role.INTERNALFRAME,
"desktop pane": controlTypes.Role.DESKTOPPANE,
"option pane": controlTypes.Role.OPTIONPANE,
"window": controlTypes.Role.WINDOW,
"frame": controlTypes.Role.FRAME,
"dialog": controlTypes.Role.DIALOG,
"color chooser": controlTypes.Role.COLORCHOOSER,
"directory pane": controlTypes.Role.DIRECTORYPANE,
"file chooser": controlTypes.Role.FILECHOOSER,
"filler": controlTypes.Role.FILLER,
"hyperlink": controlTypes.Role.LINK,
"icon": controlTypes.Role.ICON,
"label": controlTypes.Role.LABEL,
"root pane": controlTypes.Role.PANEL,
"glass pane": controlTypes.Role.PANEL,
"layered pane": controlTypes.Role.PANEL,
"list": controlTypes.Role.LIST,
"list item": controlTypes.Role.LISTITEM,
"menu bar": controlTypes.Role.MENUBAR,
"popup menu": controlTypes.Role.POPUPMENU,
"menu": controlTypes.Role.MENU,
"menu item": controlTypes.Role.MENUITEM,
"separator": controlTypes.Role.SEPARATOR,
"page tab list": controlTypes.Role.TABCONTROL,
"page tab": controlTypes.Role.TAB,
"panel": controlTypes.Role.PANEL,
"progress bar": controlTypes.Role.PROGRESSBAR,
"password text": controlTypes.Role.PASSWORDEDIT,
"push button": controlTypes.Role.BUTTON,
"toggle button": controlTypes.Role.TOGGLEBUTTON,
"check box": controlTypes.Role.CHECKBOX,
"radio button": controlTypes.Role.RADIOBUTTON,
"row header": controlTypes.Role.TABLEROWHEADER,
"scroll pane": controlTypes.Role.SCROLLPANE,
"scroll bar": controlTypes.Role.SCROLLBAR,
"view port": controlTypes.Role.VIEWPORT,
"slider": controlTypes.Role.SLIDER,
"split pane": controlTypes.Role.SPLITPANE,
"table": controlTypes.Role.TABLE,
"text": controlTypes.Role.EDITABLETEXT,
"tree": controlTypes.Role.TREEVIEW,
"tool bar": controlTypes.Role.TOOLBAR,
"tool tip": controlTypes.Role.TOOLTIP,
"status bar": controlTypes.Role.STATUSBAR,
"statusbar": controlTypes.Role.STATUSBAR,
"date editor": controlTypes.Role.DATEEDITOR,
"spin box": controlTypes.Role.SPINBUTTON,
"font chooser": controlTypes.Role.FONTCHOOSER,
"group box": controlTypes.Role.GROUPING,
"groupbox": controlTypes.Role.GROUPING,
"header": controlTypes.Role.HEADER,
"footer": controlTypes.Role.FOOTER,
"paragraph": controlTypes.Role.PARAGRAPH,
"ruler": controlTypes.Role.RULER,
"edit bar": controlTypes.Role.EDITBAR,
}
JABStatesToNVDAStates = {
"busy": controlTypes.State.BUSY,
"checked": controlTypes.State.CHECKED,
"focused": controlTypes.State.FOCUSED,
"selected": controlTypes.State.SELECTED,
"pressed": controlTypes.State.PRESSED,
"expanded": controlTypes.State.EXPANDED,
"collapsed": controlTypes.State.COLLAPSED,
"iconified": controlTypes.State.ICONIFIED,
"modal": controlTypes.State.MODAL,
"multi_line": controlTypes.State.MULTILINE,
"multiple line": controlTypes.State.MULTILINE,
"focusable": controlTypes.State.FOCUSABLE,
"editable": controlTypes.State.EDITABLE,
"selectable": controlTypes.State.SELECTABLE,
}
re_simpleXmlTag = re.compile(r"(\<[^>]+\>)+")
def _subHtmlTag(match: re.match) -> str:
"""Determines whether to replace the tag with a space or to just remove it."""
startIndex, endIndex = match.span()
return (
""
if (
startIndex == 0
or match.string[startIndex - 1].isspace()
or endIndex == len(match.string)
or match.string[endIndex].isspace()
)
else " "
)
def _processHtml(text: str) -> str:
"""Strips HTML tags from text if it is HTML"""
return re_simpleXmlTag.sub(_subHtmlTag, text) if text.startswith("<html>") else text
class JABTextInfo(textInfos.offsets.OffsetsTextInfo):
obj: "JAB"
def _getOffsetFromPoint(self, x: int, y: int) -> int:
info = self.obj.jabContext.getAccessibleTextInfo(x, y)
offset = max(min(info.indexAtPoint, info.charCount - 1), 0)
return offset
def _getBoundingRectFromOffset(self, offset: int) -> RectLTWH:
rect = self.obj.jabContext.getAccessibleTextRect(offset)
try:
return RectLTWH(rect.x, rect.y, rect.width, rect.height).toLTRB()
except ValueError:
raise LookupError
def _getCaretOffset(self) -> int:
textInfo = self.obj.jabContext.getAccessibleTextInfo(
self.obj._JABAccContextInfo.x,
self.obj._JABAccContextInfo.y,
)
offset = textInfo.caretIndex
# OpenOffice sometimes returns nonsense, so treat charCount < offset as no caret.
if offset == -1 or textInfo.charCount < offset:
raise RuntimeError("no available caret in this object")
return offset
def _setCaretOffset(self, offset: int) -> None:
self.obj.jabContext.setCaretPosition(offset)
def _getSelectionOffsets(self) -> tuple[int, int]:
info = self.obj.jabContext.getAccessibleTextSelectionInfo()
start = max(info.selectionStartIndex, 0)
end = max(info.selectionEndIndex, 0)
return (start, end)
def _setSelectionOffsets(self, start: int, end: int) -> None:
self.obj.jabContext.selectTextRange(start, end)
def _getStoryLength(self) -> int:
if not hasattr(self, "_storyLength"):
textInfo = self.obj.jabContext.getAccessibleTextInfo(
self.obj._JABAccContextInfo.x,
self.obj._JABAccContextInfo.y,
)
self._storyLength = textInfo.charCount
return self._storyLength
def _getStoryText(self) -> str:
return self._getTextRange(0, self._getStoryLength())
def _getTextRange(self, start: int, end: int) -> str:
# Java needs end of range as last character, not one past the last character
text = self.obj.jabContext.getAccessibleTextRange(start, end - 1)
return text
def _getLineNumFromOffset(self, offset: int) -> None:
return None
def _getLineOffsets(self, offset: int) -> tuple[int, int]:
(start, end) = self.obj.jabContext.getAccessibleTextLineBounds(offset)
if end == -1 and offset > 0:
# #1892: JAB returns -1 for the end insertion position
# instead of returning the offsets for the last line.
# Try one character back.
(start, end) = self.obj.jabContext.getAccessibleTextLineBounds(offset - 1)
# Java gives end as the last character, not one past the last character
end = end + 1
return (start, end)
def _getParagraphOffsets(self, offset: int) -> tuple[int, int]:
return super()._getLineOffsets(offset)
def _getFormatFieldAndOffsets(self, offset: int, formatConfig, calculateOffsets=True):
attribs: JABHandler.AccessibleTextAttributesInfo
attribs, length = self.obj.jabContext.getTextAttributesInRange(offset, self._endOffset - 1)
field = textInfos.FormatField()
field["font-family"] = attribs.fontFamily
# Translators: Abbreviation for points, a measurement of font size.
field["font-size"] = pgettext("font size", "%s pt") % str(attribs.fontSize)
field["bold"] = bool(attribs.bold)
field["italic"] = bool(attribs.italic)
field["strikethrough"] = bool(attribs.strikethrough)
field["underline"] = bool(attribs.underline)
if attribs.superscript:
field["text-position"] = TextPosition.SUPERSCRIPT
elif attribs.subscript:
field["text-position"] = TextPosition.SUBSCRIPT
else:
field["text-position"] = TextPosition.BASELINE
# TODO: Not sure how to interpret Java's alignment numbers.
return field, (offset, offset + length)
def getEmbeddedObject(self, offset: int = 0) -> "JAB":
offset += self._startOffset
# We need to count the embedded objects to determine which child to use.
# This could possibly be optimised by caching.
text = self._getTextRange(0, offset + 1)
childIndex = text.count(textUtils.OBJ_REPLACEMENT_CHAR) - 1
jabContext = self.obj.jabContext.getAccessibleChildFromContext(childIndex)
if jabContext:
return JAB(jabContext=jabContext)
raise LookupError
class JAB(Window):
def findOverlayClasses(self, clsList: list[NVDAObject]) -> None:
role = self.JABRole
if self._JABAccContextInfo.accessibleText and role in (
"text",
"password text",
"edit bar",
"view port",
"paragraph",
):
clsList.append(EditableTextWithoutAutoSelectDetection)
elif role in ("dialog", "alert"):
clsList.append(Dialog)
elif role == "combo box":
clsList.append(ComboBox)
elif role == "table":
clsList.append(Table)
elif self._hasTableParent():
clsList.append(TableCell)
elif role == "progress bar":
clsList.append(ProgressBar)
clsList.append(JAB)
def _hasTableParent(self) -> bool:
"""Lightweight check if the immediate parent is a Table.
On the fast path (parent already cached), returns immediately
without any bridge calls. On the first call, checks the parent's
role via a lightweight bridge call and only creates a full NVDAObject
when the role is "table" (which involves additional bridge calls).
"""
if hasattr(self, "_parent"):
parent = self._parent
return parent is not None and isinstance(parent, Table) and parent._jabTableInfo
parentContext = self.jabContext.getAccessibleParentFromContext()
if not parentContext:
return False
try:
parentInfo = parentContext.getAccessibleContextInfo()
except RuntimeError:
log.debugWarning("Could not get accessible context info for parent", exc_info=True)
return False
if parentInfo.role_en_US != "table":
return False
if self.indexInParent is None:
# Without indexInParent we cannot construct a valid JAB parent;
# _get_parent would also fall back to the Window ancestor here.
return False
# Parent is a table — create the full parent object reusing the context
# we already hold, so _get_parent doesn't make a redundant bridge call.
self._parent = JAB(jabContext=parentContext)
parent = self._parent
return parent is not None and isinstance(parent, Table) and parent._jabTableInfo
@classmethod
def kwargsFromSuper(cls, kwargs, relation: str | None = None) -> bool:
jabContext = None
windowHandle = kwargs["windowHandle"]
if relation == "focus":
vmID = ctypes.c_int()
accContext = JABHandler.JOBJECT64()
JABHandler.bridgeDll.getAccessibleContextWithFocus(
windowHandle,
ctypes.byref(vmID),
ctypes.byref(accContext),
)
jabContext = JABHandler.JABContext(
hwnd=windowHandle,
vmID=vmID.value,
accContext=accContext.value,
)
elif isinstance(relation, tuple):
jabContext = JABHandler.JABContext(hwnd=windowHandle)
if jabContext:
jabContext = jabContext.getAccessibleContextAt(*relation)
else:
jabContext = JABHandler.JABContext(hwnd=windowHandle)
if not jabContext:
return False
kwargs["jabContext"] = jabContext
return True
def __init__(self, relation=None, windowHandle=None, jabContext=None):
if not windowHandle:
windowHandle = jabContext.hwnd
self.windowHandle = windowHandle
self.jabContext = jabContext
super(JAB, self).__init__(windowHandle=windowHandle)
try:
self._JABAccContextInfo
except RuntimeError:
raise InvalidNVDAObject("Could not get accessible context info")
def _get__JABAccContextInfo(self):
return self.jabContext.getAccessibleContextInfo()
def _get_TextInfo(self):
if self._JABAccContextInfo.accessibleText and self.role not in [
controlTypes.Role.BUTTON,
controlTypes.Role.MENUITEM,
controlTypes.Role.MENU,
controlTypes.Role.LISTITEM,
]:
return JABTextInfo
return super(JAB, self).TextInfo
def _isEqual(self, other: Any) -> bool:
try:
return self.jabContext == other.jabContext
except: # noqa: E722
return False
def _get_keyboardShortcut(self) -> str | None:
bindings = self.jabContext.getAccessibleKeyBindings()
if not bindings or bindings.keyBindingsCount < 1:
return None
shortcutsList = []
for index in range(bindings.keyBindingsCount):
binding = bindings.keyBindingInfo[index]
# We don't support these modifiers
if binding.modifiers & (
JABHandler.AccessibleKeystroke.META
| JABHandler.AccessibleKeystroke.ALT_GRAPH
| JABHandler.AccessibleKeystroke.BUTTON1
| JABHandler.AccessibleKeystroke.BUTTON2
| JABHandler.AccessibleKeystroke.BUTTON3
):
continue
modifiers = binding.modifiers
# We assume alt if there are no modifiers at all and its not a menu item as this is clearly a nmonic
if not modifiers and self.role != controlTypes.Role.MENUITEM:
modifiers |= JABHandler.AccessibleKeystroke.ALT
keyList = [
keyLabels.localizedKeyLabels.get(l, l)
for l in JABHandler._getKeyLabels(modifiers, binding.character) # noqa: E741
]
shortcutsList.append("+".join(keyList))
return ", ".join(shortcutsList)
def _get_name(self):
name = self._JABAccContextInfo.name
return _processHtml(name)
def _get_JABRole(self):
return self._JABAccContextInfo.role_en_US
def _get_role(self):
role = JABRolesToNVDARoles.get(self.JABRole, controlTypes.Role.UNKNOWN)
if (
role in (controlTypes.Role.LABEL, controlTypes.Role.PANEL, controlTypes.Role.UNKNOWN)
and self.parent
):
parentRole = self.parent.role
if parentRole == controlTypes.Role.LIST:
return controlTypes.Role.LISTITEM
elif parentRole in (controlTypes.Role.TREEVIEW, controlTypes.Role.TREEVIEWITEM):
return controlTypes.Role.TREEVIEWITEM
elif parentRole == controlTypes.Role.TABLE:
return controlTypes.Role.TABLECELL
if role == controlTypes.Role.LABEL:
return controlTypes.Role.STATICTEXT
return role
def _get_JABStates(self):
return self._JABAccContextInfo.states_en_US
def _get_states(self):
log.debug("states: %s" % self.JABStates)
stateSet = set()
stateString = self.JABStates
stateStrings = stateString.split(",")
for state in stateStrings:
if state in JABStatesToNVDAStates:
stateSet.add(JABStatesToNVDAStates[state])
if self.role is controlTypes.Role.TOGGLEBUTTON and controlTypes.State.CHECKED in stateSet:
stateSet.discard(controlTypes.State.CHECKED)
stateSet.add(controlTypes.State.PRESSED)
if "editable" not in stateStrings and self._JABAccContextInfo.accessibleText:
stateSet.add(controlTypes.State.READONLY)
if "visible" not in stateStrings:
stateSet.add(controlTypes.State.INVISIBLE)
if "showing" not in stateStrings:
stateSet.add(controlTypes.State.OFFSCREEN)
if "expandable" not in stateStrings:
stateSet.discard(controlTypes.State.COLLAPSED)
if "enabled" not in stateStrings:
stateSet.add(controlTypes.State.UNAVAILABLE)
return stateSet
def _get_value(self):
if (
self.role
not in [
controlTypes.Role.TOGGLEBUTTON,
controlTypes.Role.CHECKBOX,
controlTypes.Role.MENU,
controlTypes.Role.MENUITEM,
controlTypes.Role.RADIOBUTTON,
controlTypes.Role.BUTTON,
]
and self._JABAccContextInfo.accessibleValue
and not self._JABAccContextInfo.accessibleText
):
return self.jabContext.getCurrentAccessibleValueFromContext()
def _get_description(self):
description = self._JABAccContextInfo.description
return _processHtml(description)
def _get_location(self):
return RectLTWH(
self._JABAccContextInfo.x,
self._JABAccContextInfo.y,
self._JABAccContextInfo.width,
self._JABAccContextInfo.height,
)
def _get_hasFocus(self) -> bool:
if controlTypes.State.FOCUSED in self.states:
return True
else:
return False
def _get_positionInfo(self):
info = super(JAB, self).positionInfo or {}
# If tree view item, try to retrieve the level via JAB
if self.role == controlTypes.Role.TREEVIEWITEM:
try:
tree = self.jabContext.getAccessibleParentWithRole("tree")
if tree:
treeDepth = tree.getObjectDepth()
selfDepth = self.jabContext.getObjectDepth()
if selfDepth > treeDepth:
info["level"] = selfDepth - treeDepth
except: # noqa: E722
pass
targets = self._getJABRelationTargets("memberOf")
for index, target in enumerate(targets):
if target == self.jabContext:
info["indexInGroup"] = index + 1
info["similarItemsInGroup"] = len(targets)
return info
parent = self.parent
if isinstance(parent, JAB) and self.role in (
controlTypes.Role.TREEVIEWITEM,
controlTypes.Role.LISTITEM,
controlTypes.Role.TAB,
):
index = self._JABAccContextInfo.indexInParent + 1
childCount = parent._JABAccContextInfo.childrenCount
info["indexInGroup"] = index
info["similarItemsInGroup"] = childCount
return info
def _get_activeChild(self):
jabContext = self.jabContext.getActiveDescendent()
if jabContext:
return JAB(jabContext=jabContext)
else:
return None
def _get_parent(self):
if not hasattr(self, "_parent"):
jabContext = self.jabContext.getAccessibleParentFromContext()
if jabContext and self.indexInParent is not None:
self._parent = JAB(jabContext=jabContext)
else:
self._parent = super(JAB, self).parent
return self._parent
def _get_next(self):
parent = self.parent
if not isinstance(parent, JAB):
return super(JAB, self).next
if self.indexInParent is None:
return None
newIndex = self.indexInParent + 1
if newIndex >= parent._JABAccContextInfo.childrenCount:
return None
jabContext = parent.jabContext.getAccessibleChildFromContext(newIndex)
if not jabContext:
return None
obj = JAB(jabContext=jabContext)
if not isinstance(obj.parent, JAB):
obj.parent = parent
if obj.indexInParent is None:
obj.indexInParent = newIndex
elif obj.indexInParent <= self.indexInParent:
return None
return obj
def _get_previous(self):
parent = self.parent
if not isinstance(parent, JAB):
return super(JAB, self).previous
if self.indexInParent is None:
return None
newIndex = self.indexInParent - 1
if newIndex < 0:
return None
jabContext = parent.jabContext.getAccessibleChildFromContext(newIndex)
if not jabContext:
return None
obj = JAB(jabContext=jabContext)
if not isinstance(obj.parent, JAB):
obj.parent = parent
if obj.indexInParent is None:
obj.indexInParent = newIndex
elif obj.indexInParent >= self.indexInParent:
return None
return obj
def _get_firstChild(self):
if self._JABAccContextInfo.childrenCount <= 0:
return None
jabContext = self.jabContext.getAccessibleChildFromContext(0)
if jabContext:
obj = JAB(jabContext=jabContext)
if not isinstance(obj.parent, JAB):
obj.parent = self
if obj.indexInParent is None:
obj.indexInParent = 0
return obj
else:
return None
def _get_lastChild(self):
if self._JABAccContextInfo.childrenCount <= 0:
return None
jabContext = self.jabContext.getAccessibleChildFromContext(self.childCount - 1)
if jabContext:
obj = JAB(jabContext=jabContext)
if not isinstance(obj.parent, JAB):
obj.parent = self
if obj.indexInParent is None:
obj.indexInParent = self.childCount - 1
return obj
else:
return None
def _get_childCount(self) -> int:
return self._JABAccContextInfo.childrenCount
def _get_children(self) -> list["JAB"]:
children = []
for index in range(self._JABAccContextInfo.childrenCount):
jabContext = self.jabContext.getAccessibleChildFromContext(index)
if jabContext:
obj = JAB(jabContext=jabContext)
if not isinstance(obj.parent, JAB):
obj.parent = self
if obj.indexInParent is None:
obj.indexInParent = index
children.append(obj)
return children
def _get_indexInParent(self) -> int | None:
index = self._JABAccContextInfo.indexInParent
if index == -1:
return None
return index
def _getJABRelationTargets(self, key: str) -> list["JABHandler.JABContext"]:
rs = self.jabContext.getAccessibleRelationSet()
targets = []
for relation in rs.relations[: rs.relationCount]:
for target in relation.targets[: relation.targetCount]:
if relation.key == key:
targets.append(JABHandler.JABContext(self.jabContext.hwnd, self.jabContext.vmID, target))
else:
JABHandler.bridgeDll.releaseJavaObject(self.jabContext.vmID, target)
return targets
def _get_flowsTo(self):
targets = self._getJABRelationTargets("flowsTo")
if targets:
return targets[0]
def _get_flowsFrom(self):
targets = self._getJABRelationTargets("flowsFrom")
if targets:
return targets[0]
def reportFocus(self):
parent = self.parent
if (
self.role in [controlTypes.Role.LIST]
and isinstance(parent, JAB)
and parent.role == controlTypes.Role.COMBOBOX
):
return
super(JAB, self).reportFocus()
def _get__actions(self):
actions = JABHandler.AccessibleActions()
JABHandler.bridgeDll.getAccessibleActions(self.jabContext.vmID, self.jabContext.accContext, actions)
return actions.actionInfo[: actions.actionsCount]
def _get_actionCount(self) -> int:
return len(self._actions)
def getActionName(self, index=None):
if index is None:
index = self.defaultActionIndex
try:
return self._actions[index].name
except IndexError:
raise NotImplementedError
def doAction(self, index=None):
if index is None:
index = self.defaultActionIndex
try:
JABHandler.bridgeDll.doAccessibleActions(
self.jabContext.vmID,
self.jabContext.accContext,
JABHandler.AccessibleActionsToDo(actionsCount=1, actions=(self._actions[index],)),
JABHandler.jint(),
)
except (IndexError, RuntimeError):
raise NotImplementedError
def _get_activeDescendant(self):
descendantFound = False
jabContext = self.jabContext
while jabContext:
try:
tempContext = jabContext.getActiveDescendent()
except: # noqa: E722
break
if not tempContext:
break
try:
depth = tempContext.getObjectDepth()
except: # noqa: E722
depth = -1
if depth <= 0 or tempContext == jabContext:
break
jabContext = tempContext
descendantFound = True
if descendantFound:
return JAB(jabContext=jabContext)
def event_gainFocus(self):
if eventHandler.isPendingEvents("gainFocus"):
return
super(JAB, self).event_gainFocus()
if eventHandler.isPendingEvents("gainFocus"):
return
activeDescendant = self.activeDescendant
if activeDescendant:
eventHandler.queueEvent("gainFocus", activeDescendant)
class ComboBox(JAB):
def _get_states(self):
states = super(ComboBox, self).states
if controlTypes.State.COLLAPSED not in states and controlTypes.State.EXPANDED not in states:
if (
self.childCount == 1
and self.firstChild
and self.firstChild.role == controlTypes.Role.POPUPMENU
):
if controlTypes.State.INVISIBLE in self.firstChild.states:
states.add(controlTypes.State.COLLAPSED)
else:
states.add(controlTypes.State.EXPANDED)
return states
def _get_activeDescendant(self):
if controlTypes.State.COLLAPSED in self.states:
return None
return super(ComboBox, self).activeDescendant
def _get_value(self):
value = super(ComboBox, self).value
if not value and not self.activeDescendant:
descendant = super(ComboBox, self).activeDescendant
if descendant:
value = descendant.name
return value
class Table(JAB):
def _get__jabTableInfo(self):
info = self.jabContext.getAccessibleTableInfo()
if info:
self._jabTableInfo = info
return info
def _get_rowCount(self) -> int | None:
if self._jabTableInfo:
return self._jabTableInfo.rowCount
def _get_columnCount(self) -> int | None:
if self._jabTableInfo:
return self._jabTableInfo.columnCount
def _get_tableID(self):
return self._jabTableInfo.jabTable.accContext.value
class TableCell(JAB):
def _get_table(self):
if self.parent and isinstance(self.parent, Table):
self.table = self.parent
return self.table
def _get_tableID(self):
return self.table.tableID
def _get_rowNumber(self) -> int:
return self.table._jabTableInfo.jabTable.getAccessibleTableRow(self.indexInParent) + 1
def _get_columnNumber(self) -> int:
return self.table._jabTableInfo.jabTable.getAccessibleTableColumn(self.indexInParent) + 1
def _get_rowHeaderText(self) -> str | None:
headerTableInfo = self.table.jabContext.getAccessibleTableRowHeader()
if headerTableInfo and headerTableInfo.jabTable:
textList = []
row = self.rowNumber - 1
for col in range(headerTableInfo.columnCount):
cellInfo = headerTableInfo.jabTable.getAccessibleTableCellInfo(row, col)
if cellInfo and cellInfo.jabContext:
obj = JAB(jabContext=cellInfo.jabContext)
if obj.name:
textList.append(obj.name)
if obj.description:
textList.append(obj.description)
jabContext = self.table._jabTableInfo.jabTable.getAccessibleTableRowDescription(row)
if jabContext:
obj = JAB(jabContext=jabContext)
if obj.name:
textList.append(obj.name)
if obj.description:
textList.append(obj.description)
return " ".join(textList)
def _get_columnHeaderText(self) -> str | None:
headerTableInfo = self.table.jabContext.getAccessibleTableColumnHeader()
if headerTableInfo and headerTableInfo.jabTable:
textList = []
col = self.columnNumber - 1
for row in range(headerTableInfo.rowCount):
cellInfo = headerTableInfo.jabTable.getAccessibleTableCellInfo(row, col)
if cellInfo and cellInfo.jabContext:
obj = JAB(jabContext=cellInfo.jabContext)
if obj.name:
textList.append(obj.name)
if obj.description:
textList.append(obj.description)
jabContext = self.table._jabTableInfo.jabTable.getAccessibleTableColumnDescription(col)
if jabContext:
obj = JAB(jabContext=jabContext)
if obj.name:
textList.append(obj.name)
if obj.description:
textList.append(obj.description)
return " ".join(textList)