Skip to content

Commit

Permalink
Merge pull request #132 from microsoft/vyokky/dev
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
vyokky authored Oct 29, 2024
2 parents 5f8178a + 6e4ee27 commit a3fa7f8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
5 changes: 4 additions & 1 deletion ufo/agents/processors/host_agent_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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:
Expand Down
81 changes: 79 additions & 2 deletions ufo/automator/ui_control/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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("%", "{%}")
1 change: 1 addition & 0 deletions ufo/automator/ui_control/openfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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()
Expand Down
4 changes: 2 additions & 2 deletions ufo/prompter/agent_prompter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
Expand Down Expand Up @@ -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]})
Expand Down

0 comments on commit a3fa7f8

Please # to comment.