ver Jan18thv3
updated get_accessibility_tree in server/main.py to give place for other os-es and desktops
This commit is contained in:
@@ -140,14 +140,15 @@ def get_terminal_output():
|
||||
if user_platform == "Linux":
|
||||
desktop: Accessible = pyatspi.Registry.getDesktop(0)
|
||||
if _has_active_terminal(desktop):
|
||||
desktop_xml: _Element = _create_node(desktop)
|
||||
desktop_xml: _Element = _create_atspi_node(desktop)
|
||||
# 1. the terminal window (frame of application is st:active) is open and active
|
||||
# 2. the terminal tab (terminal status is st:focused) is focused
|
||||
xpath = '//application[@name="gnome-terminal-server"]/frame[@st:active="true"]//terminal[@st:focused="true"]'
|
||||
terminals: List[_Element] = desktop_xml.xpath(xpath, namespaces=_accessibility_ns_map)
|
||||
output = terminals[0].text.rstrip() if len(terminals) == 1 else None
|
||||
else: # windows and macos platform is not implemented currently
|
||||
raise NotImplementedError
|
||||
#raise NotImplementedError
|
||||
return "Currently not implemented for platform {:}.".format(platform.platform()), 500
|
||||
return jsonify({"output": output, "status": "success"})
|
||||
except:
|
||||
return jsonify({"output": None, "status": "error"})
|
||||
@@ -164,7 +165,7 @@ _accessibility_ns_map = {"st": "uri:deskat:state.at-spi.gnome.org"
|
||||
}
|
||||
|
||||
|
||||
def _create_node(node: Accessible) -> _Element:
|
||||
def _create_atspi_node(node: Accessible) -> _Element:
|
||||
attribute_dict: Dict[str, Any] = {"name": node.name}
|
||||
|
||||
# States {{{ #
|
||||
@@ -285,15 +286,21 @@ def _create_node(node: Accessible) -> _Element:
|
||||
if "text" in locals() and len(text) > 0:
|
||||
xml_node.text = text
|
||||
for ch in node:
|
||||
xml_node.append(_create_node(ch))
|
||||
xml_node.append(_create_atspi_node(ch))
|
||||
return xml_node
|
||||
|
||||
|
||||
@app.route("/accessibility", methods=["GET"])
|
||||
def get_accessibility_tree():
|
||||
desktop: Accessible = pyatspi.Registry.getDesktop(0)
|
||||
desktop_xml: _Element = _create_node(desktop)
|
||||
return jsonify({"AT": lxml.etree.tostring(desktop_xml, encoding="unicode")})
|
||||
os_name: str = platform.system()
|
||||
|
||||
# AT-SPI works for KDE as well
|
||||
if os_name == "Linux":
|
||||
desktop: Accessible = pyatspi.Registry.getDesktop(0)
|
||||
desktop_xml: _Element = _create_atspi_node(desktop)
|
||||
return jsonify({"AT": lxml.etree.tostring(desktop_xml, encoding="unicode")})
|
||||
else:
|
||||
return "Currently not implemented for platform {:}.".format(platform.platform()), 500
|
||||
|
||||
|
||||
@app.route('/screen_size', methods=['POST'])
|
||||
|
||||
Reference in New Issue
Block a user