@@ -544,18 +544,21 @@ def tag_screenshot_with_action(screenshot: Image, action: str) -> Image:
544544 The tagged screenshot.
545545 """
546546 if action .startswith ("mouse_click" ):
547- coords = action [action .index ("(" ) + 1 : action .index (")" )].split ("," )
548- coords = [c .strip () for c in coords ]
549- if coords [0 ].startswith ("x=" ):
550- coords [0 ] = coords [0 ][2 :]
551- if coords [1 ].startswith ("y=" ):
552- coords [1 ] = coords [1 ][2 :]
553- x , y = float (coords [0 ].strip ()), float (coords [1 ].strip ())
554- draw = ImageDraw .Draw (screenshot )
555- radius = 5
556- draw .ellipse ((x - radius , y - radius , x + radius , y + radius ), fill = "red" , outline = "red" )
557- return screenshot
558-
547+ try :
548+ coords = action [action .index ("(" ) + 1 : action .index (")" )].split ("," )
549+ coords = [c .strip () for c in coords ]
550+ if len (coords ) != 2 :
551+ raise ValueError (f"Invalid coordinate format: { coords } " )
552+ if coords [0 ].startswith ("x=" ):
553+ coords [0 ] = coords [0 ][2 :]
554+ if coords [1 ].startswith ("y=" ):
555+ coords [1 ] = coords [1 ][2 :]
556+ x , y = float (coords [0 ].strip ()), float (coords [1 ].strip ())
557+ draw = ImageDraw .Draw (screenshot )
558+ radius = 5
559+ draw .ellipse ((x - radius , y - radius , x + radius , y + radius ), fill = "red" , outline = "red" )
560+ except (ValueError , IndexError ) as e :
561+ warning (f"Failed to parse action '{ action } ': { e } " )
559562
560563def update_screenshot (som_or_not : str ):
561564 global info
0 commit comments