MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / get_interactive_nodes

Function get_interactive_nodes

eval/eval_data/process_ac.py:23–70  ·  view source on GitHub ↗
(forest)

Source from the content-addressed store, hash-verified

21os.makedirs(images_dir, exist_ok=True)
22
23def get_interactive_nodes(forest):
24 interactives = []
25 for window in forest.windows:
26 nodes = window.tree.nodes
27 id_to_node = {getattr(node, 'unique_id', idx): node for idx, node in enumerate(nodes)}
28
29 def is_interactive(node):
30 return (
31 getattr(node, 'is_clickable', False) or
32 getattr(node, 'is_focusable', False) or
33 any(action.id in [1, 16, 32] for action in node.actions)
34 )
35
36 def iterative_dfs(root):
37 if not root:
38 return
39 stack = [root]
40 visited = set()
41 while stack:
42 node = stack.pop()
43 if id(node) in visited:
44 continue
45 visited.add(id(node))
46 if is_interactive(node):
47 bounds = {
48 'left': getattr(getattr(node, 'bounds_in_screen', None), 'left', 0),
49 'top': getattr(getattr(node, 'bounds_in_screen', None), 'top', 0),
50 'right': getattr(getattr(node, 'bounds_in_screen', None), 'right', 0),
51 'bottom': getattr(getattr(node, 'bounds_in_screen', None), 'bottom', 0)
52 }
53 interactives.append({
54 'unique_id': getattr(node, 'unique_id', None),
55 'class_name': node.class_name,
56 'content_description': node.content_description,
57 'text': node.text,
58 'resource_id': getattr(node, 'view_id_resource_name', 'N/A'),
59 'bounds': bounds
60 })
61 for child_id in reversed(node.child_ids):
62 child_node = id_to_node.get(child_id)
63 if child_node:
64 stack.append(child_node)
65
66 all_child_ids = {cid for node in nodes for cid in node.child_ids}
67 root_nodes = [node for node in nodes if getattr(node, 'unique_id', None) not in all_child_ids]
68 for root in root_nodes:
69 iterative_dfs(root)
70 return interactives
71
72with open(os.path.join(output_dir, 'data.jsonl'), 'w', encoding='utf-8') as jsonl_file:
73 pbar = tqdm(total=total_samples, desc="processing data")

Callers 1

process_ac.pyFile · 0.85

Calls 1

iterative_dfsFunction · 0.85

Tested by

no test coverage detected