diff --git a/script/auto_sliceing_operate/main.py b/script/auto_sliceing_operate/main.py index ecd14f9..3087cfe 100644 --- a/script/auto_sliceing_operate/main.py +++ b/script/auto_sliceing_operate/main.py @@ -1,6 +1,5 @@ -from utils.show_import_dialog import clickFileIMportShow from utils.import_all_file import modify_file_dialog_path_and_import_all -from utils.click_sliceing import begingClickSliceing +from utils.click_soft_button import clickFileIMportShow, clickBegingSlice import time from utils.exe_operate import start_exe, click_confirm, close @@ -24,5 +23,5 @@ def BeginSliceing(folderPath): exit() #点击开始切片 time.sleep(5) - begingClickSliceing() + clickBegingSlice() \ No newline at end of file diff --git a/script/auto_sliceing_operate/utils/click_sliceing.py b/script/auto_sliceing_operate/utils/click_sliceing.py deleted file mode 100644 index 6eb6f3f..0000000 --- a/script/auto_sliceing_operate/utils/click_sliceing.py +++ /dev/null @@ -1,76 +0,0 @@ -import uiautomation as auto - - - -# 遍历所有控件 找到 -def findAndClickFileImportShow(control, depth=0): - for child in control.GetChildren(): - # print(child) - # print(' ' * depth + f"{child.ControlType}: {child.Name} | {child.AutomationId}") - if child.Name == "切片及打印": - # 点击和 child 同组的第二个元素(即 control 的子控件中的第二个) - siblings = control.GetChildren() # 获取所有同级元素 - # print(f"\n找到目标控件: {child.Name}") - # print(f"同级元素数量: {len(siblings)}") - - # 打印所有同级元素信息,方便调试 - for i, sibling in enumerate(siblings): - marker = " <-- 这是找到的目标" if sibling == child else "" - print(f" 同级元素[{i}]: {sibling.ControlType} | {sibling.Name} | {sibling.AutomationId}{marker}") - - # 确保有至少2个同级元素 - if len(siblings) >= 2: - target = siblings[2] # 第二个元素(索引从0开始) - print(f"\n准备点击同级第二个元素:") - print(f" 控件类型: {target.ControlType}") - print(f" 控件名称: {target.Name}") - print(f" 自动化ID: {target.AutomationId}") - - # 尝试多种点击方式 - try: - # 方法1: 直接点击 - target.Click() - print("✓ 使用 Click() 方法点击成功") - return True - except Exception as e: - print(f"✗ Click() 失败: {e}") - try: - # 方法2: 使用 Invoke(如果是可调用的控件) - target.Invoke() - print("✓ 使用 Invoke() 方法点击成功") - return True - except Exception as e2: - print(f"✗ Invoke() 失败: {e2}") - try: - # 方法3: 先设置焦点再点击 - target.SetFocus() - import time - time.sleep(0.1) - target.Click() - print("✓ 使用 SetFocus() + Click() 方法点击成功") - return True - except Exception as e3: - print(f"✗ SetFocus() + Click() 失败: {e3}") - # 方法4: 使用鼠标点击坐标 - try: - rect = target.BoundingRectangle - # BoundingRectangle 是一个矩形对象,计算中心点 - x = rect.left + ((rect.right - rect.left) / 2) - y = rect.top + ((rect.bottom - rect.top) / 2) - auto.Click(x, y) - print(f"✓ 使用坐标点击成功: ({x}, {y})") - return True - except Exception as e4: - print(f"✗ 坐标点击失败: {e4}") - else: - print(f"✗ 同级元素数量不足,只有 {len(siblings)} 个") - return False - else: - findAndClickFileImportShow(child, depth + 1) - -def begingClickSliceing(): - control = auto.WindowControl(searchDepth=1, Name='赛纳3D打印控制系统 V1.4.3.2') - clickRes = findAndClickFileImportShow(control) - return clickRes - -# clickFileIMportShow() \ No newline at end of file diff --git a/script/auto_sliceing_operate/utils/show_import_dialog.py b/script/auto_sliceing_operate/utils/click_soft_button.py similarity index 85% rename from script/auto_sliceing_operate/utils/show_import_dialog.py rename to script/auto_sliceing_operate/utils/click_soft_button.py index 97dc7e3..fa7c942 100644 --- a/script/auto_sliceing_operate/utils/show_import_dialog.py +++ b/script/auto_sliceing_operate/utils/click_soft_button.py @@ -3,7 +3,7 @@ import uiautomation as auto # 遍历所有控件 找到 -def findAndClickFileImportShow(control, depth=0): +def findAndClickFileImportShow(control, depth=0,index=1): for child in control.GetChildren(): # print(child) # print(' ' * depth + f"{child.ControlType}: {child.Name} | {child.AutomationId}") @@ -20,8 +20,8 @@ def findAndClickFileImportShow(control, depth=0): # 确保有至少2个同级元素 if len(siblings) >= 2: - target = siblings[1] # 第二个元素(索引从0开始) - print(f"\n准备点击同级第二个元素:") + target = siblings[index] # 第二个元素(索引从0开始) + print(f"\n准备点击同级{index+1}个元素:") print(f" 控件类型: {target.ControlType}") print(f" 控件名称: {target.Name}") print(f" 自动化ID: {target.AutomationId}") @@ -68,9 +68,14 @@ def findAndClickFileImportShow(control, depth=0): else: findAndClickFileImportShow(child, depth + 1) +# 点击导入文件按钮 def clickFileIMportShow(): control = auto.WindowControl(searchDepth=1, Name='赛纳3D打印控制系统 V1.4.3.2') - clickRes = findAndClickFileImportShow(control) + clickRes = findAndClickFileImportShow(control,index=1) return clickRes -# clickFileIMportShow() \ No newline at end of file +# 点击开始切片按钮 +def clickBegingSlice(): + control = auto.WindowControl(searchDepth=1, Name='赛纳3D打印控制系统 V1.4.3.2') + clickRes = findAndClickFileImportShow(control,index=2) + return clickRes