Add impress examples; remove the auto-saving pyautogui commands change to libreoffice pre-setting

This commit is contained in:
Timothyxxx
2024-01-29 21:34:58 +08:00
parent 17514907d9
commit 343813a29b
29 changed files with 163 additions and 44 deletions

View File

@@ -18,7 +18,7 @@ from .libreoffice import check_libre_locale
from .pdf import check_pdf_pages from .pdf import check_pdf_pages
from .slides import check_presenter_console_disable, check_image_stretch_and_center, check_slide_numbers_color, \ from .slides import check_presenter_console_disable, check_image_stretch_and_center, check_slide_numbers_color, \
compare_pptx_files, check_strikethrough, \ compare_pptx_files, check_strikethrough, \
check_slide_orientation_Portrait, evaluate_presentation_fill_to_rgb_distance, check_left_panel check_slide_orientation_Portrait, evaluate_presentation_fill_to_rgb_distance, check_left_panel, check_transition
# from .table import check_sheet_list, check_xlsx_freeze, check_xlsx_zoom, check_data_validations # from .table import check_sheet_list, check_xlsx_freeze, check_xlsx_zoom, check_data_validations
from .table import compare_table, compare_csv from .table import compare_table, compare_csv
from .thunderbird import check_thunderbird_prefs, check_thunderbird_filter from .thunderbird import check_thunderbird_prefs, check_thunderbird_filter

View File

@@ -253,15 +253,15 @@ def evaluate_colored_words_in_tables(file_path1, file_path2):
def check_highlighted_words(file_path1, file_path2): def check_highlighted_words(file_path1, file_path2):
if not compare_docx_files(file_path1, file_path2): # if not compare_docx_files(file_path1, file_path2):
return 0 # return 0
# Extract content.xml from the .odt file # Extract content.xml from the .odt file
extract_dir = file_path1 + "_extracted" extract_dir = file_path1 + "_extracted"
with zipfile.ZipFile(file_path1, 'r') as zip_ref: with zipfile.ZipFile(file_path1, 'r') as zip_ref:
zip_ref.extractall(extract_dir) zip_ref.extractall(extract_dir)
content_xml_path = os.path.join(extract_dir, 'content.xml') content_xml_path = os.path.join(extract_dir, 'content.xml')
with open(content_xml_path, 'r') as file: with open(content_xml_path, 'r', encoding="utf-8") as file:
content_xml = file.read() content_xml = file.read()
# Check for yellow highlights in the content.xml # Check for yellow highlights in the content.xml

View File

@@ -1,5 +1,6 @@
import logging import logging
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import zipfile
from math import sqrt from math import sqrt
from pptx import Presentation from pptx import Presentation
@@ -189,7 +190,8 @@ def compare_pptx_files(file1_path, file2_path, **options):
if run1.font.underline != run2.font.underline and examine_font_underline: if run1.font.underline != run2.font.underline and examine_font_underline:
return 0 return 0
if ('strike' in run1.font._element.attrib) != ('strike' in run2.font._element.attrib) and examine_strike_through: if ('strike' in run1.font._element.attrib) != (
'strike' in run2.font._element.attrib) and examine_strike_through:
return 0 return 0
# fixme: Actually there are more properties to be compared, but we cannot get them through pptx # fixme: Actually there are more properties to be compared, but we cannot get them through pptx
@@ -278,3 +280,41 @@ def check_left_panel(accessibility_tree):
# Left panel is not open # Left panel is not open
return 0.0 return 0.0
def check_transition(pptx_file, rules):
slide_idx = rules['slide_idx']
transition_type = rules['transition_type']
# Use the zipfile module to open the .pptx file
with zipfile.ZipFile(pptx_file, 'r') as zip_ref:
# Get the slide XML file
slide_name = 'ppt/slides/slide{}.xml'.format(slide_idx + 1)
try:
zip_ref.getinfo(slide_name)
except KeyError:
# Slide does not exist
return 0.
with zip_ref.open(slide_name) as slide_file:
# 解析XML
tree = ET.parse(slide_file)
root = tree.getroot()
# XML namespace
namespaces = {
'a': 'http://schemas.openxmlformats.org/drawingml/2006/main',
'p': 'http://schemas.openxmlformats.org/presentationml/2006/main',
}
# Search for the transition element
transition = root.find('.//p:transition', namespaces)
if transition is not None:
# Check if the transition is an expected transition
dissolve = transition.find('.//p:{}'.format(transition_type), namespaces)
if dissolve is not None:
return 1.
else:
return 0.
else:
return 0.

View File

@@ -3,10 +3,89 @@
"snapshot": "libreoffice_impress", "snapshot": "libreoffice_impress",
"instruction": "Could you help me add silde transition \"dissolve\" to my first page?", "instruction": "Could you help me add silde transition \"dissolve\" to my first page?",
"source": "https://www.libreofficehelp.com/add-animations-transitions-libreoffice-impress-slides/", "source": "https://www.libreofficehelp.com/add-animations-transitions-libreoffice-impress-slides/",
"config": [], "config": [
{
"type": "download",
"parameters": {
"files": [
{
"url": "https://drive.usercontent.google.com/download?id=1A9nNj3hWBB0Bnr2Cf7zHs3WFiTKdEeNt&export=download&authuser=0&confirm=t&uuid=7c0f29fd-1f1a-4d48-b717-5c677373e615&at=APZUnTX9YQH_-UbVyFRLblwZ3rAn:1706530787330",
"path": "Desktop/Ch4 Video Effect.pptx"
}
]
}
},
{
"type": "open",
"parameters": {
"path": "Desktop/Ch4 Video Effect.pptx"
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; import time; time.sleep(4); pyautogui.doubleClick(x=960, y=540); time.sleep(0.5);pyautogui.mouseDown(); pyautogui.mouseUp(); time.sleep(0.5);"
]
}
}
],
"trajectory": "trajectories/", "trajectory": "trajectories/",
"related_apps": [ "related_apps": [
"" "libreoffice_impress"
], ],
"evaluator": "evaluation_dir" "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "Ch4 Video Effect.pptx - LibreOffice Impress",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5);"
]
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
}
],
"func": "check_transition",
"expected": {
"type": "rule",
"rules": {
"slide_idx": 0,
"transition_type": "dissolve"
}
},
"result": {
"type": "vm_file",
"path": "Desktop/Ch4 Video Effect.pptx",
"dest": "Ch4 Video Effect.pptx"
}
}
} }

View File

@@ -33,7 +33,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; time.sleep(4); pyautogui.doubleClick(x=200, y=600); time.sleep(0.5);pyautogui.mouseDown(); pyautogui.mouseUp(); time.sleep(0.5);" "import pyautogui; import time; time.sleep(4); pyautogui.doubleClick(x=200, y=650); time.sleep(0.5);pyautogui.mouseDown(); pyautogui.mouseUp(); time.sleep(0.5);"
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -57,7 +57,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5);"
] ]
} }
} }

View File

@@ -68,7 +68,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -48,7 +48,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

View File

@@ -47,7 +47,7 @@
"command": [ "command": [
"python", "python",
"-c", "-c",
"import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); pyautogui.press('down'); time.sleep(0.5); pyautogui.press('enter')" "import pyautogui; import time; pyautogui.hotkey('ctrl', 's'); time.sleep(0.5); "
] ]
} }
} }

24
main.py
View File

@@ -46,12 +46,12 @@ def human_agent():
Runs the Gym environment with human input. Runs the Gym environment with human input.
""" """
with open("evaluation_examples/examples/libreoffice_writer/72b810ef-4156-4d09-8f08-a0cf57e7cefe.json", "r") as f: with open("evaluation_examples/examples/libreoffice_writer/6a33f9b9-0a56-4844-9c3f-96ec3ffb3ba2.json", "r") as f:
example = json.load(f) example = json.load(f)
example["snapshot"] = "base18" example["snapshot"] = "exp_v1"
env = DesktopEnv( env = DesktopEnv(
path_to_vm=r"D:\Ubuntu\Ubuntu\Ubuntu.vmx", path_to_vm=r"C:\Users\tianbaox\Documents\Virtual Machines\Ubuntu\Ubuntu.vmx",
action_space="computer_13", action_space="computer_13",
task_config=example task_config=example
) )
@@ -60,14 +60,14 @@ def human_agent():
done = False done = False
trajectory = [ trajectory = [
{ # {
"action_type": "MOVE_TO", # "action_type": "MOVE_TO",
"parameters": { # "parameters": {
"x": 754, # "x": 754,
"y": 1057 # "y": 1057
} # }
}, # },
{"action_type": "CLICK", "parameters": {"button": "right", "num_clicks": 1}} # {"action_type": "CLICK", "parameters": {"button": "right", "num_clicks": 1}}
] ]
for i in range(len(trajectory)): for i in range(len(trajectory)):
@@ -91,7 +91,7 @@ def human_agent():
logger.info("The episode is done.") logger.info("The episode is done.")
break break
#input("PAUSING") input("PAUSING")
result = env.evaluate() result = env.evaluate()
logger.info("Result: %.2f", result) logger.info("Result: %.2f", result)