| 39 | |
| 40 | |
| 41 | def get_id_from_element(elem): |
| 42 | bounds = elem.attrib["bounds"][1:-1].split("][") |
| 43 | x1, y1 = map(int, bounds[0].split(",")) |
| 44 | x2, y2 = map(int, bounds[1].split(",")) |
| 45 | elem_w, elem_h = x2 - x1, y2 - y1 |
| 46 | if "resource-id" in elem.attrib and elem.attrib["resource-id"]: |
| 47 | elem_id = elem.attrib["resource-id"].replace(":", ".").replace("/", "_") |
| 48 | else: |
| 49 | elem_id = f"{elem.attrib['class']}_{elem_w}_{elem_h}" |
| 50 | if "content-desc" in elem.attrib and elem.attrib["content-desc"] and len(elem.attrib["content-desc"]) < 20: |
| 51 | content_desc = elem.attrib['content-desc'].replace("/", "_").replace(" ", "").replace(":", "_") |
| 52 | elem_id += f"_{content_desc}" |
| 53 | return elem_id |
| 54 | |
| 55 | |
| 56 | def traverse_tree(xml_path, elem_list, attrib, add_index=False): |