(action: Action)
| 249 | |
| 250 | @beartype |
| 251 | def action2create_function(action: Action) -> str: |
| 252 | match (action["action_type"]): |
| 253 | case ActionTypes.NONE: |
| 254 | return "create_none_action()" |
| 255 | # mouse wheel and keyboard action |
| 256 | case ActionTypes.SCROLL: |
| 257 | direction = "up" if "up" in action["direction"] else "down" |
| 258 | return f"create_scroll_action({repr(direction)})" |
| 259 | case ActionTypes.KEY_PRESS: |
| 260 | return f"create_key_press_action({repr(action['key_comb'])})" |
| 261 | # inter-page actions |
| 262 | case ActionTypes.PAGE_FOCUS: |
| 263 | return f"create_page_focus_action({action['page_number']})" |
| 264 | case ActionTypes.NEW_TAB: |
| 265 | return "create_new_tab_action()" |
| 266 | case ActionTypes.GO_BACK: |
| 267 | return "create_go_back_action()" |
| 268 | case ActionTypes.GO_FORWARD: |
| 269 | return "create_go_forward_action()" |
| 270 | case ActionTypes.GOTO_URL: |
| 271 | return f"create_goto_url_action({repr(action['url'])})" |
| 272 | case ActionTypes.PAGE_CLOSE: |
| 273 | return "create_page_close_action()" |
| 274 | |
| 275 | # low-level keyboard and mouse actions |
| 276 | case ActionTypes.MOUSE_CLICK: |
| 277 | return f"create_mouse_click_action({action['coords'][0]}, {action['coords'][1]})" |
| 278 | case ActionTypes.MOUSE_HOVER: |
| 279 | return f"create_mouse_hover_action({action['coords'][0]}, {action['coords'][1]})" |
| 280 | case ActionTypes.KEYBOARD_TYPE: |
| 281 | return f"create_keyboard_type_action({list(map(lambda x: _id2key[x], action['text']))})" |
| 282 | |
| 283 | # mid-level keyboard and mouse actions |
| 284 | case ActionTypes.CLICK: |
| 285 | args = [] |
| 286 | args.append(f"element_id={repr(action['element_id'])}") |
| 287 | args.append( |
| 288 | f"element_role={repr(_id2role[action['element_role']])}" |
| 289 | ) |
| 290 | args.append(f"element_name={repr(action['element_name'])}") |
| 291 | args.append(f"pw_code={repr(action['pw_code'])}") |
| 292 | args_str = ", ".join(args) |
| 293 | return f"create_click_action({args_str})" |
| 294 | case ActionTypes.HOVER: |
| 295 | args = [] |
| 296 | args.append(f"element_id={repr(action['element_id'])}") |
| 297 | args.append( |
| 298 | f"element_role={repr(_id2role[action['element_role']])}" |
| 299 | ) |
| 300 | args.append(f"element_name={repr(action['element_name'])}") |
| 301 | args.append(f"pw_code={repr(action['pw_code'])}") |
| 302 | args_str = ", ".join(args) |
| 303 | return f"create_hover_action({args_str})" |
| 304 | case ActionTypes.TYPE: |
| 305 | args = [] |
| 306 | text = "".join(map(lambda x: _id2key[x], action["text"])) |
| 307 | args.append(f"text={repr(text)}") |
| 308 | args.append(f"element_id={repr(action['element_id'])}") |
no outgoing calls