diff --git a/desktop_env/evaluators/getters/__init__.py b/desktop_env/evaluators/getters/__init__.py index dd81060..83cd30e 100644 --- a/desktop_env/evaluators/getters/__init__.py +++ b/desktop_env/evaluators/getters/__init__.py @@ -7,4 +7,4 @@ from .misc import get_rule, get_accessibility_tree from .replay import get_replay from .vlc import get_vlc_playing_info, get_vlc_config from .vscode import get_vscode_config -from .impress import get_audio_in_slide +# from .impress import get_audio_in_slide diff --git a/desktop_env/evaluators/getters/gimp.py b/desktop_env/evaluators/getters/gimp.py index e69de29..dc179dc 100644 --- a/desktop_env/evaluators/getters/gimp.py +++ b/desktop_env/evaluators/getters/gimp.py @@ -0,0 +1,32 @@ +import logging +import os +from typing import Dict + +logger = logging.getLogger("desktopenv.getters.gimp") + + +def get_gimp_config(env, config: Dict[str, str]): + """ + Gets the config setting of GIMP. + """ + + os_type = env.vm_platform + + if os_type == "Linux": + config_path = \ + env.controller.execute_python_command(f"import os; print(" + f"os" + f".path.expanduser(" + f"'~/.config/GIMP/2.10/" + f"{config['file_name']}'))")[ + 'output'].strip() + # TODO: Add support for macOS and Windows + else: + raise Exception("Unsupported operating system", os_type) + + _path = os.path.join(env.cache_dir, config["dest"]) + content = env.controller.get_file(config_path) + with open(_path, "wb") as f: + f.write(content) + + return _path diff --git a/desktop_env/evaluators/metrics/__init__.py b/desktop_env/evaluators/metrics/__init__.py index 49dfd70..9fe0ca8 100644 --- a/desktop_env/evaluators/metrics/__init__.py +++ b/desktop_env/evaluators/metrics/__init__.py @@ -20,3 +20,11 @@ from .vlc import is_vlc_playing, is_vlc_recordings_folder, is_vlc_fullscreen, co compare_videos from .thunderbird import check_thunderbird_prefs, check_thunderbird_filter from .vscode import compare_text_file, compare_config, compare_answer, is_extension_installed, check_json_settings, check_json_keybindings +from .gimp import ( + check_brightness_decrease_and_structure_sim, + check_contrast_increase_and_structure_sim, + check_saturation_increase_and_structure_sim, + check_file_exists_and_structure_sim, + check_triangle_position, + check_structure_sim, +) \ No newline at end of file diff --git a/desktop_env/evaluators/metrics/gimp.py b/desktop_env/evaluators/metrics/gimp.py index 99cd5f7..a24c112 100644 --- a/desktop_env/evaluators/metrics/gimp.py +++ b/desktop_env/evaluators/metrics/gimp.py @@ -2,6 +2,7 @@ import os from PIL import Image, ImageStat from skimage.metrics import structural_similarity as ssim import numpy as np +import sexpdata def get_gimp_export_path(): @@ -286,6 +287,8 @@ def check_structure_sim(src_path, tgt_path): Check if the structure of the two images are similar gimp:2a729ded-3296-423d-aec4-7dd55ed5fbb3 """ + print("src_path:", src_path) + print("tgt_path:", tgt_path) img_src = Image.open(src_path) img_tgt = Image.open(tgt_path) structure_same = structure_check_by_ssim(img_src, img_tgt) @@ -312,10 +315,46 @@ def check_contrast_increase_and_structure_sim(src_path, tgt_path): return higher_contrast and structure_same +def check_config_status(actual_config_path, rule): + """ + Check if the GIMP status is as expected + """ + with open(actual_config_path, 'r') as f: + content = f.readlines() + + for line in content: + if line.startswith('#') or line == '\n': + continue + items = line.strip().lstrip('(').rstrip(')\n').split() + if isinstance(rule["key"], str): + if items[0] == rule["key"] and items[-1] == rule["value"]: + return True + elif isinstance(rule["key"], list) and len(rule["key"]) == 2: + if items[0] == rule["key"][0] \ + and items[1] == rule["key"][1] \ + and items[-1] == rule["value"]: + return True + return False + + if __name__ == "__main__": - image1_path = "../Downloads/1.png" - image2_path = "../Downloads/edited_darker.png" + actual_config_path = "../../../cache/sessionrc_test" + rule = { + "key": "hide-docks", + "value": "no" + } + print(check_config_status(actual_config_path, rule)) - decrease_brightness(image1_path, image2_path) + actual_config_path = "../../../cache/action-history_test" + rule = { + "key": ["history-item", "\"filters-vignette\""], + "value": "1" + } + print(check_config_status(actual_config_path, rule)) - increase_saturation(image1_path, image2_path) + actual_config_path = "../../../cache/gimprc_test" + rule = { + "key": "undo-levels", + "value": "100" + } + print(check_config_status(actual_config_path, rule))