ver Jun28th (#51)
reduced time to acquire AT from at-spi from ~5 s to ~3.5 s
* refined acquisition of States and Attributes
* canceled acquisition of Component when node is not showing and
visible according to the document
(https://gnome.pages.gitlab.gnome.org/at-spi2-core/libatspi/iface.Component.html)
* pruned windowcoord and parentcoord, merged size and screencoord into
one at-spi invocation
* canceled acquisition of Document
* refined acquisition of RoleName
This commit is contained in:
@@ -4,7 +4,7 @@ import platform
|
||||
import shlex
|
||||
import subprocess, signal
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Optional, Sequence
|
||||
from typing import List, Dict, Tuple
|
||||
|
||||
import Xlib
|
||||
@@ -22,7 +22,7 @@ if platform_name=="Linux":
|
||||
import pyatspi
|
||||
from pyatspi import Accessible, StateType, STATE_SHOWING
|
||||
from pyatspi import Action as ATAction
|
||||
from pyatspi import Component, Document
|
||||
from pyatspi import Component #, Document
|
||||
from pyatspi import Text as ATText
|
||||
from pyatspi import Value as ATValue
|
||||
|
||||
@@ -217,54 +217,57 @@ def _create_atspi_node(node: Accessible, depth: int = 0, flag: Optional[str] = N
|
||||
states: List[StateType] = node.getState().get_states()
|
||||
for st in states:
|
||||
state_name: str = StateType._enum_lookup[st]
|
||||
if len(state_name.split("_", maxsplit=1)[1].lower()) == 0:
|
||||
state_name: str = state_name.split("_", maxsplit=1)[1].lower()
|
||||
if len(state_name) == 0:
|
||||
continue
|
||||
attribute_dict[
|
||||
"{{{:}}}{:}".format(_accessibility_ns_map["st"], state_name.split("_", maxsplit=1)[1].lower())] = "true"
|
||||
"{{{:}}}{:}".format(_accessibility_ns_map["st"], state_name)] = "true"
|
||||
# }}} States #
|
||||
|
||||
# Attributes {{{ #
|
||||
attributes: List[str] = node.getAttributes()
|
||||
for attrbt in attributes:
|
||||
attribute_name: str
|
||||
attribute_value: str
|
||||
attribute_name, attribute_value = attrbt.split(":", maxsplit=1)
|
||||
attributes: Dict[str, str] = node.get_attributes()
|
||||
for attribute_name, attribute_value in attributes.items():
|
||||
if len(attribute_name) == 0:
|
||||
continue
|
||||
attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["attr"], attribute_name)] = attribute_value
|
||||
# }}} Attributes #
|
||||
|
||||
# Component {{{ #
|
||||
try:
|
||||
component: Component = node.queryComponent()
|
||||
except NotImplementedError:
|
||||
pass
|
||||
else:
|
||||
attribute_dict["{{{:}}}screencoord".format(_accessibility_ns_map["cp"])] = str(
|
||||
component.getPosition(pyatspi.XY_SCREEN))
|
||||
attribute_dict["{{{:}}}windowcoord".format(_accessibility_ns_map["cp"])] = str(
|
||||
component.getPosition(pyatspi.XY_WINDOW))
|
||||
attribute_dict["{{{:}}}parentcoord".format(_accessibility_ns_map["cp"])] = str(
|
||||
component.getPosition(pyatspi.XY_PARENT))
|
||||
attribute_dict["{{{:}}}size".format(_accessibility_ns_map["cp"])] = str(component.getSize())
|
||||
if attribute_dict.get("{{{:}}}visible".format(_accessibility_ns_map["st"]), "false") == "true"\
|
||||
and attribute_dict.get("{{{:}}}showing".format(_accessibility_ns_map["st"]), "false") == "true":
|
||||
try:
|
||||
component: Component = node.queryComponent()
|
||||
except NotImplementedError:
|
||||
pass
|
||||
else:
|
||||
bbox: Sequence[int] = component.getExtents(pyatspi.XY_SCREEN)
|
||||
attribute_dict["{{{:}}}screencoord".format(_accessibility_ns_map["cp"])] =\
|
||||
str(tuple(bbox[0:2]))
|
||||
#attribute_dict["{{{:}}}screencoord".format(_accessibility_ns_map["cp"])] = str(
|
||||
#component.getPosition(pyatspi.XY_SCREEN))
|
||||
#attribute_dict["{{{:}}}windowcoord".format(_accessibility_ns_map["cp"])] = str(
|
||||
#component.getPosition(pyatspi.XY_WINDOW))
|
||||
#attribute_dict["{{{:}}}parentcoord".format(_accessibility_ns_map["cp"])] = str(
|
||||
#component.getPosition(pyatspi.XY_PARENT))
|
||||
attribute_dict["{{{:}}}size".format(_accessibility_ns_map["cp"])] = str(tuple(bbox[2:]))
|
||||
# }}} Component #
|
||||
|
||||
# Document {{{ #
|
||||
try:
|
||||
document: Document = node.queryDocument()
|
||||
except NotImplementedError:
|
||||
pass
|
||||
else:
|
||||
attribute_dict["{{{:}}}locale".format(_accessibility_ns_map["doc"])] = document.getLocale()
|
||||
attribute_dict["{{{:}}}pagecount".format(_accessibility_ns_map["doc"])] = str(document.getPageCount())
|
||||
attribute_dict["{{{:}}}currentpage".format(_accessibility_ns_map["doc"])] = str(document.getCurrentPageNumber())
|
||||
for attrbt in document.getAttributes():
|
||||
attribute_name: str
|
||||
attribute_value: str
|
||||
attribute_name, attribute_value = attrbt.split(":", maxsplit=1)
|
||||
if len(attribute_name) == 0:
|
||||
continue
|
||||
attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["docattr"], attribute_name)] = attribute_value
|
||||
#try:
|
||||
#document: Document = node.queryDocument()
|
||||
#except NotImplementedError:
|
||||
#pass
|
||||
#else:
|
||||
#attribute_dict["{{{:}}}locale".format(_accessibility_ns_map["doc"])] = document.getLocale()
|
||||
#attribute_dict["{{{:}}}pagecount".format(_accessibility_ns_map["doc"])] = str(document.getPageCount())
|
||||
#attribute_dict["{{{:}}}currentpage".format(_accessibility_ns_map["doc"])] = str(document.getCurrentPageNumber())
|
||||
#for attrbt in document.getAttributes():
|
||||
#attribute_name: str
|
||||
#attribute_value: str
|
||||
#attribute_name, attribute_value = attrbt.split(":", maxsplit=1)
|
||||
#if len(attribute_name) == 0:
|
||||
#continue
|
||||
#attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["docattr"], attribute_name)] = attribute_value
|
||||
# }}} Document #
|
||||
|
||||
# Text {{{ #
|
||||
@@ -346,10 +349,8 @@ def _create_atspi_node(node: Accessible, depth: int = 0, flag: Optional[str] = N
|
||||
] = action.getKeyBinding(i)
|
||||
# }}} Action #
|
||||
|
||||
if node.getRoleName().strip() == "":
|
||||
node_role_name = "unknown"
|
||||
else:
|
||||
node_role_name = node.getRoleName().replace(" ", "-")
|
||||
raw_role_name: str = node.getRoleName().strip()
|
||||
node_role_name = (raw_role_name or "unknown").replace(" ", "-")
|
||||
|
||||
xml_node = lxml.etree.Element(
|
||||
node_role_name,
|
||||
|
||||
Reference in New Issue
Block a user