Skip to content

Commit 231fc86

Browse files
authored
Fix missing time imports on Linux grounding actions and place_text closure (#157)
Adds missing `import time` for the Linux `open()` action and `UBUNTU_APP_SETUP` script, and refactors `place_text` in `behavior_narrator` to take explicit x,y parameters instead of capturing loop variables.
1 parent aa9e3df commit 231fc86

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

gui_agents/s3/agents/grounding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def agent_action(func):
3030
UBUNTU_APP_SETUP = f"""import subprocess;
3131
import difflib;
3232
import pyautogui;
33+
import time;
3334
pyautogui.press('escape');
3435
time.sleep(0.5);
3536
output = subprocess.check_output(['wmctrl', '-lx']);
@@ -394,7 +395,7 @@ def open(self, app_or_filename: str):
394395
app_or_filename:str, the name of the application or filename to open
395396
"""
396397
if self.platform == "linux":
397-
return f"import pyautogui; pyautogui.hotkey('win'); time.sleep(0.5); pyautogui.write({repr(app_or_filename)}); time.sleep(1.0); pyautogui.hotkey('enter'); time.sleep(0.5)"
398+
return f"import pyautogui; import time; pyautogui.hotkey('win'); time.sleep(0.5); pyautogui.write({repr(app_or_filename)}); time.sleep(1.0); pyautogui.hotkey('enter'); time.sleep(0.5)"
398399
elif self.platform == "darwin":
399400
return f"import pyautogui; import time; pyautogui.hotkey('command', 'space', interval=0.5); pyautogui.typewrite({repr(app_or_filename)}); pyautogui.press('enter'); time.sleep(1.0)"
400401
elif self.platform == "windows":

gui_agents/s3/bbon/behavior_narrator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,31 @@ def mark_action(mouse_actions: list[str], img: Image):
4848
width = max(0, min(img.width - 1, width))
4949
height = max(0, min(img.height - 1, height))
5050

51-
def place_text(label, color):
51+
def place_text(label, color, x, y):
5252
bbox = draw.textbbox((0, 0), label, font=font)
5353
text_w, text_h = (
5454
bbox[2] - bbox[0],
5555
bbox[3] - bbox[1],
5656
) # Measure text size
5757
offset_x, offset_y = -5, 5 # Default offset
58-
if width + offset_x + text_w > img.width: # Out of bounds on right
58+
if x + offset_x + text_w > img.width: # Out of bounds on right
5959
offset_x = -text_w - 5
60-
if height + offset_y + text_h > img.height: # Out of bounds on bottom
60+
if y + offset_y + text_h > img.height: # Out of bounds on bottom
6161
offset_y = -text_h - 5
62-
if width + offset_x < 0: # Out of bounds on left
62+
if x + offset_x < 0: # Out of bounds on left
6363
offset_x = 5
64-
if height + offset_y < 0: # Out of bounds on top
64+
if y + offset_y < 0: # Out of bounds on top
6565
offset_y = 5
6666
draw.text(
67-
(width + offset_x, height + offset_y), label, fill=color, font=font
67+
(x + offset_x, y + offset_y), label, fill=color, font=font
6868
)
6969

7070
if mouse_action.startswith("pyautogui.click"):
7171
draw.circle((width, height), radius=3, fill=(255, 0, 0))
72-
place_text("Click", (255, 0, 0))
72+
place_text("Click", (255, 0, 0), width, height)
7373
if mouse_action.startswith("pyautogui.moveTo"):
7474
draw.circle((width, height), radius=3, fill=(0, 0, 255))
75-
place_text("MoveTo", (0, 0, 255))
75+
place_text("MoveTo", (0, 0, 255), width, height)
7676
drag_start_height, drag_start_width = height, width
7777
if mouse_action.startswith("pyautogui.dragTo"):
7878
draw.line(
@@ -81,7 +81,7 @@ def place_text(label, color):
8181
width=2,
8282
)
8383
draw.circle((width, height), radius=3, fill=(0, 255, 0))
84-
place_text("DragTo", (0, 255, 0))
84+
place_text("DragTo", (0, 255, 0), width, height)
8585

8686
@staticmethod
8787
def get_mouse_action_representation(mouse_actions: list[str]) -> str:

0 commit comments

Comments
 (0)