Fix minor bugs of multiple apps examples
This commit is contained in:
@@ -367,7 +367,7 @@ class SetupController:
|
||||
context = browser.contexts[0]
|
||||
|
||||
page = context.new_page() # Create a new page (tab) within the existing context
|
||||
page.goto(url)
|
||||
page.goto(url, timeout=60000)
|
||||
logger.info(f"Opened tab {i + 1}: {url}")
|
||||
|
||||
if i == 0:
|
||||
|
||||
@@ -84,7 +84,6 @@ class DesktopEnv(gym.Env):
|
||||
|
||||
# Initialize emulator and controller
|
||||
logger.info("Initializing...")
|
||||
self._config_screen_size()
|
||||
self._start_emulator()
|
||||
self.vm_ip = self._get_vm_ip()
|
||||
self.controller = PythonController(vm_ip=self.vm_ip)
|
||||
@@ -105,60 +104,6 @@ class DesktopEnv(gym.Env):
|
||||
self._step_no: int = 0
|
||||
self.action_history: List[Dict[str, any]] = []
|
||||
|
||||
def _config_screen_size(self):
|
||||
"""
|
||||
fixme: Experimental features, will cause unexpected error when system corrupt
|
||||
"""
|
||||
def calculate_vram_size(width, height, bits_per_pixel=32):
|
||||
"""
|
||||
Calculate VRAM size for given width, height, and color depth.
|
||||
Color depth defaults to 32 bits per pixel.
|
||||
"""
|
||||
bytes_per_pixel = bits_per_pixel // 8
|
||||
vram_size = width * height * bytes_per_pixel
|
||||
return vram_size
|
||||
|
||||
if not os.path.isfile(self.path_to_vm):
|
||||
logger.warning(f"The specified vmx file does not exist: {self.path_to_vm}")
|
||||
return False
|
||||
|
||||
width, height = self.vm_screen_size
|
||||
vramSize = calculate_vram_size(width, height)
|
||||
|
||||
try:
|
||||
with open(self.path_to_vm, 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
new_lines = []
|
||||
for line in lines:
|
||||
if "svga.autodetect" in line:
|
||||
continue
|
||||
elif "svga.vramSize" in line:
|
||||
continue
|
||||
elif "displayWidth" in line:
|
||||
continue
|
||||
elif "displayHeight" in line:
|
||||
continue
|
||||
else:
|
||||
new_lines.append(line)
|
||||
|
||||
# Append new settings for screen size and VRAM.
|
||||
new_lines.append(f'svga.autodetect = "TRUE"\n')
|
||||
new_lines.append(f'svga.vramSize = "{vramSize}"\n')
|
||||
new_lines.append(f'displayWidth = "{width}"\n')
|
||||
new_lines.append(f'displayHeight = "{height}"\n')
|
||||
|
||||
with open(self.path_to_vm, 'w') as file:
|
||||
file.writelines(new_lines)
|
||||
logger.info(f"Screen size for {self.path_to_vm} set to {width}x{height} with VRAM size {vramSize} bytes")
|
||||
return True
|
||||
except IOError as e:
|
||||
logger.error(f"An IOError occurred: {e}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return False
|
||||
|
||||
def _start_emulator(self):
|
||||
while True:
|
||||
try:
|
||||
@@ -280,7 +225,6 @@ class DesktopEnv(gym.Env):
|
||||
_execute_command(["vmrun", "-T", "ws", "revertToSnapshot", self.path_to_vm, self.snapshot_path])
|
||||
time.sleep(5)
|
||||
|
||||
self._config_screen_size()
|
||||
print(self.vm_screen_size)
|
||||
logger.info("Starting emulator...")
|
||||
self._start_emulator()
|
||||
|
||||
@@ -12,6 +12,8 @@ def compare_image_list(pred_img_path_list: Union[str, List[str]],
|
||||
pred_img_path_list = [pred_img_path_list]
|
||||
gold_img_path_list = [gold_img_path_list]
|
||||
for pred_img_path, gold_img_path in zip(pred_img_path_list, gold_img_path_list):
|
||||
if not pred_img_path or not gold_img_path:
|
||||
return 0.0
|
||||
pred_img = Image.open(pred_img_path)
|
||||
gold_img = Image.open(gold_img_path)
|
||||
diff = ImageChops.difference(pred_img, gold_img)
|
||||
|
||||
Reference in New Issue
Block a user