From 7ccf3b4d7112c081a1ce1e035e8cc24db08833a5 Mon Sep 17 00:00:00 2001 From: vyokky <7678676@qq.com> Date: Mon, 28 Oct 2024 16:54:42 +0800 Subject: [PATCH 1/2] fix openapp bug --- ufo/agents/processors/host_agent_processor.py | 5 ++++- ufo/automator/ui_control/openfile.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ufo/agents/processors/host_agent_processor.py b/ufo/agents/processors/host_agent_processor.py index cdd4d946..ed261e86 100644 --- a/ufo/agents/processors/host_agent_processor.py +++ b/ufo/agents/processors/host_agent_processor.py @@ -165,7 +165,10 @@ def execute_action(self) -> None: """ # When the required application is not opened, try to open the application and set the focus to the application window. - if self.app_to_open is not None: + if ( + isinstance(self.app_to_open, dict) + and self.app_to_open.get("APP", None) is not None + ): new_app_window = self.host_agent.app_file_manager(self.app_to_open) self.control_text = new_app_window.window_text() else: diff --git a/ufo/automator/ui_control/openfile.py b/ufo/automator/ui_control/openfile.py index 0d7a8561..2058a369 100644 --- a/ufo/automator/ui_control/openfile.py +++ b/ufo/automator/ui_control/openfile.py @@ -47,6 +47,7 @@ def execute_code(self, args: Dict) -> bool: (ps. filepath can be empty.) :return: The result of the execution or error. """ + self.APP = args.get("APP", "") self.file_path = args.get("file_path", "") self.check_open_status() From 6e4ee27b3b071b8d5265f2e6d0b46dc7350bb89a Mon Sep 17 00:00:00 2001 From: vyokky <7678676@qq.com> Date: Tue, 29 Oct 2024 19:39:44 +0800 Subject: [PATCH 2/2] fix bug for the last screenshot --- ufo/automator/ui_control/controller.py | 81 +++++++++++++++++++++++++- ufo/prompter/agent_prompter.py | 4 +- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/ufo/automator/ui_control/controller.py b/ufo/automator/ui_control/controller.py index 6958613d..87df3fba 100644 --- a/ufo/automator/ui_control/controller.py +++ b/ufo/automator/ui_control/controller.py @@ -162,8 +162,9 @@ def set_edit_text(self, params: Dict[str, str]) -> str: args = {"text": text} else: method_name = "type_keys" - text = text.replace("\n", "{ENTER}") - text = text.replace("\t", "{TAB}") + + # Transform the text according to the tags. + text = TextTransformer.transform_text(text, "all") args = {"keys": text, "pause": inter_key_pause, "with_spaces": True} try: @@ -622,3 +623,79 @@ def name(cls) -> str: :return: The name of the atomic command. """ return "" + + +class TextTransformer: + """ + The text transformer class. + """ + + @staticmethod + def transform_text(text: str, transform_tag: str) -> str: + """ + Transform the text. + :param text: The text to transform. + :param transform_tag: The tag to transform. + :return: The transformed text. + """ + + if transform_tag == "all": + transform_tag = "+\n\t^%" + + if "\n" in transform_tag: + text = TextTransformer.transform_enter(text) + if "\t" in transform_tag: + text = TextTransformer.transform_tab(text) + if "+" in transform_tag: + text = TextTransformer.transform_plus(text) + if "^" in transform_tag: + text = TextTransformer.transform_caret(text) + if "%" in transform_tag: + text = TextTransformer.transform_percent(text) + + return text + + @staticmethod + def transform_enter(text: str) -> str: + """ + Transform the enter key. + :param text: The text to transform. + :return: The transformed text. + """ + return text.replace("\n", "{ENTER}") + + @staticmethod + def transform_tab(text: str) -> str: + """ + Transform the tab key. + :param text: The text to transform. + :return: The transformed text. + """ + return text.replace("\t", "{TAB}") + + @staticmethod + def transform_plus(text: str) -> str: + """ + Transform the plus key. + :param text: The text to transform. + :return: The transformed text. + """ + return text.replace("+", "{+}") + + @staticmethod + def transform_caret(text: str) -> str: + """ + Transform the caret key. + :param text: The text to transform. + :return: The transformed text. + """ + return text.replace("^", "{^}") + + @staticmethod + def transform_percent(text: str) -> str: + """ + Transform the percent key. + :param text: The text to transform. + :return: The transformed text. + """ + return text.replace("%", "{%}") diff --git a/ufo/prompter/agent_prompter.py b/ufo/prompter/agent_prompter.py index de0554af..28202f4f 100644 --- a/ufo/prompter/agent_prompter.py +++ b/ufo/prompter/agent_prompter.py @@ -319,7 +319,7 @@ def user_content_construction( if include_last_screenshot: screenshot_text += ["Screenshot for the last step:"] - screenshot_text += ["Current Screenshots:", "Annotated Screenshot:"] + screenshot_text += ["Current Screenshots:", "Annotated Screenshot:"] for i, image in enumerate(image_list): user_content.append({"type": "text", "text": screenshot_text[i]}) @@ -580,7 +580,7 @@ def user_content_construction( if include_last_screenshot: screenshot_text += ["Screenshot for the last step:"] - screenshot_text += ["Current Screenshots:", "Annotated Screenshot:"] + screenshot_text += ["Current Screenshots:", "Annotated Screenshot:"] for i, image in enumerate(image_list): user_content.append({"type": "text", "text": screenshot_text[i]})