Merge branch 'main' of https://github.com/xlang-ai/DesktopEnv
This commit is contained in:
@@ -29,7 +29,7 @@ from .chrome import (
|
||||
from .file import get_cloud_file, get_vm_file, get_cache_file, get_content_from_vm_file
|
||||
from .general import get_vm_command_line, get_vm_terminal_output, get_vm_command_error
|
||||
from .gimp import get_gimp_config_file
|
||||
from .impress import get_audio_in_slide
|
||||
from .impress import get_audio_in_slide, get_background_image_in_slide
|
||||
from .info import get_vm_screen_size, get_vm_window_size, get_vm_wallpaper, get_list_directory
|
||||
from .misc import get_rule, get_accessibility_tree, get_rule_relativeTime
|
||||
from .replay import get_replay
|
||||
|
||||
@@ -589,6 +589,10 @@ def get_active_url_from_accessTree(env, config):
|
||||
if len(elements) == 0:
|
||||
print("no elements found")
|
||||
return None
|
||||
elif elements[-1].text is None:
|
||||
print("no text found")
|
||||
return None
|
||||
|
||||
active_tab_url = config["goto_prefix"] + elements[0].text if "goto_prefix" in config.keys() else "https://" + \
|
||||
elements[0].text
|
||||
print("active tab url now: {}".format(active_tab_url))
|
||||
|
||||
@@ -7,6 +7,67 @@ from typing import Dict
|
||||
from desktop_env.evaluators.getters.file import get_vm_file
|
||||
|
||||
|
||||
def get_background_image_in_slide(env, config: Dict[str, str]):
|
||||
ppt_file_path, slide_index, dest = config["ppt_file_path"], int(config["slide_index"]), config["dest"]
|
||||
image_id, image_file_path = None, None
|
||||
|
||||
ppt_file_localhost_path = get_vm_file(env, {"path": ppt_file_path, "dest": os.path.split(ppt_file_path)[-1]})
|
||||
|
||||
with zipfile.ZipFile(ppt_file_localhost_path, 'r') as myzip:
|
||||
slide1_xml_file = 'ppt/slides/slide{}.xml'.format(slide_index + 1)
|
||||
# firstly, check whether the background image is used in the slide
|
||||
if slide1_xml_file not in myzip.namelist(): return None
|
||||
with myzip.open(slide1_xml_file) as f:
|
||||
# Parse the XML tree from the relationships file
|
||||
tree = ET.parse(f)
|
||||
root = tree.getroot()
|
||||
bg_tag = "{http://schemas.openxmlformats.org/presentationml/2006/main}bgPr"
|
||||
image_tag = "{http://schemas.openxmlformats.org/drawingml/2006/main}blip"
|
||||
attr_tag = "{http://schemas.openxmlformats.org/officeDocument/2006/relationships}embed"
|
||||
for child in root.iter(bg_tag):
|
||||
try:
|
||||
for element in child.iter(image_tag):
|
||||
image_id = element.attrib[attr_tag]
|
||||
break
|
||||
except: pass
|
||||
if image_id is not None: break
|
||||
else: return None
|
||||
|
||||
# next, extract the background image from the slide
|
||||
slide1_rels_file = 'ppt/slides/_rels/slide{}.xml.rels'.format(slide_index + 1)
|
||||
if slide1_rels_file in myzip.namelist():
|
||||
with myzip.open(slide1_rels_file) as f:
|
||||
# Parse the XML tree from the relationships file
|
||||
tree = ET.parse(f)
|
||||
root = tree.getroot()
|
||||
# Define the namespace used in the relationships file
|
||||
namespaces = {'r': 'http://schemas.openxmlformats.org/package/2006/relationships'}
|
||||
# Look for all relationship elements that have a type attribute for image
|
||||
for rel in root.findall('r:Relationship', namespaces):
|
||||
# Check if the relationship is for an image file
|
||||
if 'image' in rel.attrib['Type'] and rel.attrib['Id'] == image_id:
|
||||
target = rel.attrib['Target']
|
||||
if target.startswith('..'):
|
||||
# Resolve the relative path to get the correct path within the zip file
|
||||
image_file_path = os.path.normpath(os.path.join('ppt/slides', target))
|
||||
# Replace backslashes with forward slashes for ZIP compatibility
|
||||
image_file_path = image_file_path.replace('\\', '/')
|
||||
tmpdirname = os.path.dirname(ppt_file_localhost_path)
|
||||
myzip.extract(image_file_path, tmpdirname)
|
||||
image_file_path = os.path.join(tmpdirname, image_file_path)
|
||||
return image_file_path
|
||||
else: # absolute path
|
||||
assert target.startswith("file://"), target
|
||||
image_file_path = target[7:]
|
||||
break
|
||||
if image_file_path is None:
|
||||
return None
|
||||
|
||||
else:
|
||||
# Get the audio file from vm and return the file path in the host
|
||||
return get_vm_file(env, {"path": image_file_path, "dest": dest})
|
||||
|
||||
|
||||
def get_audio_in_slide(env, config: Dict[str, str]):
|
||||
ppt_file_path, slide_index, dest = config["ppt_file_path"], int(config["slide_index"]), config["dest"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user