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