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 shlex
|
||||||
import subprocess, signal
|
import subprocess, signal
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional, Sequence
|
||||||
from typing import List, Dict, Tuple
|
from typing import List, Dict, Tuple
|
||||||
|
|
||||||
import Xlib
|
import Xlib
|
||||||
@@ -22,7 +22,7 @@ if platform_name=="Linux":
|
|||||||
import pyatspi
|
import pyatspi
|
||||||
from pyatspi import Accessible, StateType, STATE_SHOWING
|
from pyatspi import Accessible, StateType, STATE_SHOWING
|
||||||
from pyatspi import Action as ATAction
|
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 Text as ATText
|
||||||
from pyatspi import Value as ATValue
|
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()
|
states: List[StateType] = node.getState().get_states()
|
||||||
for st in states:
|
for st in states:
|
||||||
state_name: str = StateType._enum_lookup[st]
|
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
|
continue
|
||||||
attribute_dict[
|
attribute_dict[
|
||||||
"{{{:}}}{:}".format(_accessibility_ns_map["st"], state_name.split("_", maxsplit=1)[1].lower())] = "true"
|
"{{{:}}}{:}".format(_accessibility_ns_map["st"], state_name)] = "true"
|
||||||
# }}} States #
|
# }}} States #
|
||||||
|
|
||||||
# Attributes {{{ #
|
# Attributes {{{ #
|
||||||
attributes: List[str] = node.getAttributes()
|
attributes: Dict[str, str] = node.get_attributes()
|
||||||
for attrbt in attributes:
|
for attribute_name, attribute_value in attributes.items():
|
||||||
attribute_name: str
|
|
||||||
attribute_value: str
|
|
||||||
attribute_name, attribute_value = attrbt.split(":", maxsplit=1)
|
|
||||||
if len(attribute_name) == 0:
|
if len(attribute_name) == 0:
|
||||||
continue
|
continue
|
||||||
attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["attr"], attribute_name)] = attribute_value
|
attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["attr"], attribute_name)] = attribute_value
|
||||||
# }}} Attributes #
|
# }}} Attributes #
|
||||||
|
|
||||||
# Component {{{ #
|
# Component {{{ #
|
||||||
try:
|
if attribute_dict.get("{{{:}}}visible".format(_accessibility_ns_map["st"]), "false") == "true"\
|
||||||
component: Component = node.queryComponent()
|
and attribute_dict.get("{{{:}}}showing".format(_accessibility_ns_map["st"]), "false") == "true":
|
||||||
except NotImplementedError:
|
try:
|
||||||
pass
|
component: Component = node.queryComponent()
|
||||||
else:
|
except NotImplementedError:
|
||||||
attribute_dict["{{{:}}}screencoord".format(_accessibility_ns_map["cp"])] = str(
|
pass
|
||||||
component.getPosition(pyatspi.XY_SCREEN))
|
else:
|
||||||
attribute_dict["{{{:}}}windowcoord".format(_accessibility_ns_map["cp"])] = str(
|
bbox: Sequence[int] = component.getExtents(pyatspi.XY_SCREEN)
|
||||||
component.getPosition(pyatspi.XY_WINDOW))
|
attribute_dict["{{{:}}}screencoord".format(_accessibility_ns_map["cp"])] =\
|
||||||
attribute_dict["{{{:}}}parentcoord".format(_accessibility_ns_map["cp"])] = str(
|
str(tuple(bbox[0:2]))
|
||||||
component.getPosition(pyatspi.XY_PARENT))
|
#attribute_dict["{{{:}}}screencoord".format(_accessibility_ns_map["cp"])] = str(
|
||||||
attribute_dict["{{{:}}}size".format(_accessibility_ns_map["cp"])] = str(component.getSize())
|
#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 #
|
# }}} Component #
|
||||||
|
|
||||||
# Document {{{ #
|
# Document {{{ #
|
||||||
try:
|
#try:
|
||||||
document: Document = node.queryDocument()
|
#document: Document = node.queryDocument()
|
||||||
except NotImplementedError:
|
#except NotImplementedError:
|
||||||
pass
|
#pass
|
||||||
else:
|
#else:
|
||||||
attribute_dict["{{{:}}}locale".format(_accessibility_ns_map["doc"])] = document.getLocale()
|
#attribute_dict["{{{:}}}locale".format(_accessibility_ns_map["doc"])] = document.getLocale()
|
||||||
attribute_dict["{{{:}}}pagecount".format(_accessibility_ns_map["doc"])] = str(document.getPageCount())
|
#attribute_dict["{{{:}}}pagecount".format(_accessibility_ns_map["doc"])] = str(document.getPageCount())
|
||||||
attribute_dict["{{{:}}}currentpage".format(_accessibility_ns_map["doc"])] = str(document.getCurrentPageNumber())
|
#attribute_dict["{{{:}}}currentpage".format(_accessibility_ns_map["doc"])] = str(document.getCurrentPageNumber())
|
||||||
for attrbt in document.getAttributes():
|
#for attrbt in document.getAttributes():
|
||||||
attribute_name: str
|
#attribute_name: str
|
||||||
attribute_value: str
|
#attribute_value: str
|
||||||
attribute_name, attribute_value = attrbt.split(":", maxsplit=1)
|
#attribute_name, attribute_value = attrbt.split(":", maxsplit=1)
|
||||||
if len(attribute_name) == 0:
|
#if len(attribute_name) == 0:
|
||||||
continue
|
#continue
|
||||||
attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["docattr"], attribute_name)] = attribute_value
|
#attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["docattr"], attribute_name)] = attribute_value
|
||||||
# }}} Document #
|
# }}} Document #
|
||||||
|
|
||||||
# Text {{{ #
|
# Text {{{ #
|
||||||
@@ -346,10 +349,8 @@ def _create_atspi_node(node: Accessible, depth: int = 0, flag: Optional[str] = N
|
|||||||
] = action.getKeyBinding(i)
|
] = action.getKeyBinding(i)
|
||||||
# }}} Action #
|
# }}} Action #
|
||||||
|
|
||||||
if node.getRoleName().strip() == "":
|
raw_role_name: str = node.getRoleName().strip()
|
||||||
node_role_name = "unknown"
|
node_role_name = (raw_role_name or "unknown").replace(" ", "-")
|
||||||
else:
|
|
||||||
node_role_name = node.getRoleName().replace(" ", "-")
|
|
||||||
|
|
||||||
xml_node = lxml.etree.Element(
|
xml_node = lxml.etree.Element(
|
||||||
node_role_name,
|
node_role_name,
|
||||||
|
|||||||
Reference in New Issue
Block a user