Skip to content

Commit

Permalink
select table api
Browse files Browse the repository at this point in the history
  • Loading branch information
vyokky committed May 3, 2024
1 parent 9bdcaf9 commit 18ec79a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
28 changes: 27 additions & 1 deletion ufo/automator/app_apis/word/wordclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def get_default_command_registry() -> Dict[str, WinCOMCommand]:
"""
mappping = {
"insert_table": InsertTableCommand,
"select_text": SelectTextCommand
"select_text": SelectTextCommand,
"select_table": SelectTableCommand
}
return mappping

Expand Down Expand Up @@ -72,7 +73,19 @@ def select_text(self, text: str) -> None:
return f"Text {text} is selected."
else:
return f"Text {text} is not found."


def select_table(self, number: int) -> None:
"""
Select a table in the document.
:param number: The number of the table.
"""
tables = self.com_object.Tables
if not number or number < 1 or number > tables.Count:
return f"Table number {number} is out of range."

tables[number].Select()
return f"Table {number} is selected."



Expand Down Expand Up @@ -107,3 +120,16 @@ def execute(self):
return self.receiver.select_text(self.params.get("text"))



class SelectTableCommand(WinCOMCommand):
"""
The command to select a table.
"""
def execute(self):
"""
Execute the command to select a table in the document.
:return: The selected table.
"""
return self.receiver.select_table(self.params.get("number"))


2 changes: 1 addition & 1 deletion ufo/module/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def start_new_round(self) -> None:
self._status = "COMPLETE"
else:
self.request = self.plan_reader.next_step()
utils.print_with_color("Starting round {round} for the subtask:".format(round=self._round), "yellow")
utils.print_with_color("Starting step {round}:".format(round=self._round), "yellow")
utils.print_with_color(self.request, "cyan")
self._current_round = self.create_round()
self._current_round.set_application_window(self.app_window)
Expand Down
13 changes: 13 additions & 0 deletions ufo/prompts/apps/word/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ SelectText:
[3] Example: select_text(text="Hello")
[4] Available control item: The Document control item in the Word app.
[5] Return: A string of the selected text if successful, otherwise a text not found message.
SelectTable:
summary: |-
"SelectTable" is to select a table in a Word document for further operations, such as deleting the table or changing the border color.
usage: |-
[1] API call: select_table(number: int)
[2] Args:
- number: The index number of the table to be selected.
[3] Example: select_table(number=1)
[4] Available control item: The Document control item in the Word app.
[5] Return: A string of the selected table if successful, otherwise an out of range message.

0 comments on commit 18ec79a

Please sign in to comment.