Merge remote-tracking branch 'origin/main'
# Conflicts: # desktop_env/controllers/setup.py
This commit is contained in:
@@ -197,8 +197,10 @@ class PythonController:
|
||||
if "text" not in parameters:
|
||||
raise Exception(f"Unknown parameters: {parameters}")
|
||||
# deal with special ' and \ characters
|
||||
text = parameters["text"].replace("\\", "\\\\").replace("'", "\\'")
|
||||
self.execute_python_command(f"pyautogui.typewrite('{text}')")
|
||||
# text = parameters["text"].replace("\\", "\\\\").replace("'", "\\'")
|
||||
# self.execute_python_command(f"pyautogui.typewrite('{text}')")
|
||||
text = parameters["text"]
|
||||
self.execute_python_command("pyautogui.typewrite({:})".format(repr(text)))
|
||||
|
||||
elif action_type == "PRESS":
|
||||
if "key" not in parameters:
|
||||
|
||||
@@ -205,11 +205,15 @@ class SetupController:
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error("An error occurred while trying to send the request: %s", e)
|
||||
|
||||
def _launch_setup(self, command: Union[str, List[str]]):
|
||||
def _launch_setup(self, command: Union[str, List[str]], shell: bool = False):
|
||||
if not command:
|
||||
raise Exception("Empty command to launch.")
|
||||
|
||||
payload = json.dumps({"command": command})
|
||||
if not shell and isinstance(command, str) and len(command.split()) > 1:
|
||||
logger.warning("Command should be a list of strings. Now it is a string. Will split it by space.")
|
||||
command = command.split()
|
||||
|
||||
payload = json.dumps({"command": command, "shell": shell})
|
||||
headers = {"Content-Type": "application/json"}
|
||||
|
||||
try:
|
||||
@@ -241,7 +245,7 @@ class SetupController:
|
||||
|
||||
while not terminates:
|
||||
try:
|
||||
response = requests.post(self.http_server_setup_root + "/execute", headers=headers, data=payload)
|
||||
response = requests.post(self.http_server + "/setup" + "/execute", headers=headers, data=payload)
|
||||
if response.status_code == 200:
|
||||
results: Dict[str, str] = response.json()
|
||||
if stdout:
|
||||
|
||||
@@ -14,3 +14,4 @@ from .gimp import increase_saturation, decrease_brightness, check_file_exists, c
|
||||
from .general import check_csv, check_accessibility_tree, check_list, run_sqlite3
|
||||
from .thunderbird import check_thunderbird_prefs, check_thunderbird_filter
|
||||
from .vscode import compare_text_file, compare_config, compare_answer, is_extension_installed
|
||||
from .impress import check_slide_numbers_color, compare_pptx_files, check_for_two_lines
|
||||
|
||||
@@ -1,4 +1,75 @@
|
||||
from pptx import Presentation
|
||||
import os
|
||||
|
||||
def is_red_color(color):
|
||||
#judge if the color is red
|
||||
print(color.rgb)
|
||||
return color and color.rgb == (255, 0, 0)
|
||||
|
||||
def get_master_placeholder_color(prs):
|
||||
# get the color of the placeholder
|
||||
masters = prs.slide_masters
|
||||
for idx, master in enumerate(masters):
|
||||
for placeholder in master.placeholders:
|
||||
if placeholder.has_text_frame and placeholder.text == "<number>":
|
||||
text_frame = placeholder.text_frame
|
||||
|
||||
if text_frame.paragraphs:
|
||||
first_paragraph = text_frame.paragraphs[0]
|
||||
return first_paragraph.font.color
|
||||
return None
|
||||
|
||||
|
||||
def check_slide_numbers_color(pptx_file_path):
|
||||
presentation = Presentation(pptx_file_path)
|
||||
|
||||
for i, slide in enumerate(presentation.slides):
|
||||
for shape in slide.shapes:
|
||||
# check if the shape is a text box
|
||||
if hasattr(shape, "text"):
|
||||
if shape.text.isdigit():
|
||||
# "SlidePlaceholder" is the name of the placeholder in the master slide
|
||||
page_number_text = shape.text
|
||||
font_color = get_master_placeholder_color(presentation)
|
||||
print(font_color)
|
||||
return 1 if font_color is not None and is_red_color(font_color) else 0
|
||||
|
||||
def compare_pptx_files(file1_path, file2_path):
|
||||
prs1 = Presentation(file1_path)
|
||||
prs2 = Presentation(file2_path)
|
||||
|
||||
# compare the number of slides
|
||||
if len(prs1.slides) != len(prs2.slides):
|
||||
return 0
|
||||
|
||||
# compare the content of each slide
|
||||
for slide1, slide2 in zip(prs1.slides, prs2.slides):
|
||||
# check if the shapes are the same
|
||||
for shape1, shape2 in zip(slide1.shapes, slide2.shapes):
|
||||
if hasattr(shape1, "text") and hasattr(shape2, "text"):
|
||||
if shape1.text != shape2.text:
|
||||
return 0
|
||||
return 1
|
||||
|
||||
def has_two_lines_on_page(slide):
|
||||
line_count = 0
|
||||
for shape in slide.shapes:
|
||||
if shape.shape_type == 1: # 1 表示 Line 形状
|
||||
line_count += 1
|
||||
if line_count >= 2:
|
||||
return True
|
||||
return False
|
||||
|
||||
def check_for_two_lines(prs):
|
||||
prs = Presentation(prs)
|
||||
for i, slide in enumerate(prs.slides):
|
||||
if has_two_lines_on_page(slide):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def check_file_exists(directory, filename):
|
||||
file_path = os.path.join(directory, filename)
|
||||
return 1 if os.path.isfile(file_path) else 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
path1 = "../../任务数据/LibreOffice Impress/Change_Color_Slide_Number_gold_textbox.pptx"
|
||||
|
||||
@@ -63,14 +63,15 @@ def execute_command():
|
||||
@app.route('/setup/launch', methods=["POST"])
|
||||
def launch_app():
|
||||
data = request.json
|
||||
command: List[str] = data.get("command", [])
|
||||
shell = data.get("shell", False)
|
||||
command: List[str] = data.get("command", "" if shell else [])
|
||||
|
||||
if isinstance(command, str):
|
||||
command = shlex.split(command)
|
||||
|
||||
try:
|
||||
subprocess.Popen(command)
|
||||
return "{:} launched successfully".format(" ".join(command))
|
||||
subprocess.Popen(command, shell=shell)
|
||||
return "{:} launched successfully".format(command if shell else " ".join(command))
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "message": str(e)}), 500
|
||||
|
||||
|
||||
@@ -5,3 +5,4 @@ git+https://github.com/moses-palmer/pynput.git@refs/pull/541/head # to make sure
|
||||
requests
|
||||
flask
|
||||
numpy
|
||||
lxml
|
||||
|
||||
Reference in New Issue
Block a user