Fix bugs of a11y tree when the tag is empty

This commit is contained in:
Timothyxxx
2024-01-23 14:37:54 +08:00
parent 7e61ab7e53
commit 303c89411e

View File

@@ -33,6 +33,7 @@ logger = app.logger
recording_process = None # fixme: this is a temporary solution for recording, need to be changed to support multiple-process
recording_path = "/tmp/recording.mp4"
@app.route('/setup/execute', methods=['POST'])
@app.route('/execute', methods=['POST'])
def execute_command():
@@ -172,11 +173,10 @@ def _create_atspi_node(node: Accessible) -> _Element:
states: List[StateType] = node.getState().get_states()
for st in states:
state_name: str = StateType._enum_lookup[st]
attribute_dict["{{{:}}}{:}" \
.format(_accessibility_ns_map["st"]
, state_name.split("_", maxsplit=1)[1].lower()
)
] = "true"
if len(state_name.split("_", maxsplit=1)[1].lower()) == 0:
continue
attribute_dict[
"{{{:}}}{:}".format(_accessibility_ns_map["st"], state_name.split("_", maxsplit=1)[1].lower())] = "true"
# }}} States #
# Attributes {{{ #
@@ -185,11 +185,9 @@ def _create_atspi_node(node: Accessible) -> _Element:
attribute_name: str
attribute_value: str
attribute_name, attribute_value = attrbt.split(":", maxsplit=1)
attribute_dict["{{{:}}}{:}" \
.format(_accessibility_ns_map["attr"]
, attribute_name
)
] = attribute_value
if len(attribute_name) == 0:
continue
attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["attr"], attribute_name)] = attribute_value
# }}} Attributes #
# Component {{{ #
@@ -220,11 +218,9 @@ def _create_atspi_node(node: Accessible) -> _Element:
attribute_name: str
attribute_value: str
attribute_name, attribute_value = attrbt.split(":", maxsplit=1)
attribute_dict["{{{:}}}{:}" \
.format(_accessibility_ns_map["docattr"]
, attribute_name
)
] = attribute_value
if len(attribute_name) == 0:
continue
attribute_dict["{{{:}}}{:}".format(_accessibility_ns_map["docattr"], attribute_name)] = attribute_value
# }}} Document #
# Text {{{ #
@@ -279,9 +275,15 @@ def _create_atspi_node(node: Accessible) -> _Element:
] = action.getKeyBinding(i)
# }}} Action #
xml_node = lxml.etree.Element(node.getRoleName().replace(" ", "-")
, attrib=attribute_dict
, nsmap=_accessibility_ns_map
if node.getRoleName().strip() == "":
node_role_name = "unknown"
else:
node_role_name = node.getRoleName().replace(" ", "-")
xml_node = lxml.etree.Element(
node_role_name,
attrib=attribute_dict,
nsmap=_accessibility_ns_map
)
if "text" in locals() and len(text) > 0:
xml_node.text = text
@@ -651,6 +653,7 @@ def activate_window():
return "Window activated successfully", 200
@app.route("/setup/close_window", methods=["POST"])
def close_window():
data = request.json
@@ -696,6 +699,7 @@ def close_window():
return "Window closed successfully.", 200
@app.route('/start_recording', methods=['POST'])
def start_recording():
global recording_process