feat: improve AT-SPI labeling
This commit is contained in:
+38
-3
@@ -84,9 +84,44 @@ def scan(width, height):
|
||||
x, y = max(0, rect.x), max(0, rect.y)
|
||||
right, bottom = min(width, rect.x + rect.width), min(height, rect.y + rect.height)
|
||||
if right > x and bottom > y:
|
||||
targets.append({"id": str(len(targets) + 1), "path": path, "app": app,
|
||||
"name": (node.name or "")[:200], "role": role,
|
||||
"bounds": [x, y, right - x, bottom - y]})
|
||||
states = []
|
||||
for name, constant in (
|
||||
("focused", pyatspi.STATE_FOCUSED),
|
||||
("editable", pyatspi.STATE_EDITABLE),
|
||||
("enabled", pyatspi.STATE_ENABLED),
|
||||
("checked", pyatspi.STATE_CHECKED),
|
||||
("active", pyatspi.STATE_ACTIVE),
|
||||
("selected", pyatspi.STATE_SELECTED),
|
||||
("selectable", pyatspi.STATE_SELECTABLE),
|
||||
("expanded", pyatspi.STATE_EXPANDED),
|
||||
("collapsed", pyatspi.STATE_COLLAPSED),
|
||||
("busy", pyatspi.STATE_BUSY),
|
||||
):
|
||||
try:
|
||||
if state.contains(constant):
|
||||
states.append(name)
|
||||
except Exception:
|
||||
pass
|
||||
value = None
|
||||
try:
|
||||
text_val = node.queryText().getText(0, -1)
|
||||
if text_val is not None:
|
||||
value = text_val[:200]
|
||||
except Exception:
|
||||
pass
|
||||
if value is None:
|
||||
try:
|
||||
value = str(node.queryValue().currentValue)
|
||||
except Exception:
|
||||
pass
|
||||
target = {
|
||||
"id": str(len(targets) + 1), "path": path, "app": app,
|
||||
"name": (node.name or "")[:200], "role": role,
|
||||
"bounds": [x, y, right - x, bottom - y], "states": states,
|
||||
}
|
||||
if value is not None and (value != target["name"] or "editable" in states):
|
||||
target["value"] = value
|
||||
targets.append(target)
|
||||
for index in range(min(node.childCount, 1500)):
|
||||
if visited >= 1500 or len(targets) >= 100:
|
||||
truncated = True
|
||||
|
||||
Reference in New Issue
Block a user