From 59f2884aac351f749b35fb41959750c334a929ed Mon Sep 17 00:00:00 2001 From: Devilflasher <33209468+devilflasher@users.noreply.github.com> Date: Mon, 28 Apr 2025 09:06:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=89=B9=E9=87=8F=E6=89=93=E5=BC=80?= =?UTF-8?q?=E7=BD=91=E9=A1=B5,=E6=94=AF=E6=8C=81=20=20Chrome=20=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5=E5=92=8C=20Chrome=20=E6=8F=92=E4=BB=B6=202.?= =?UTF-8?q?=20=E6=8C=87=E5=AE=9A=E6=96=87=E6=9C=AC=E8=BE=93=E5=85=A5,?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=8D=E5=88=B6=E5=86=85=E5=AE=B9=E5=88=B0?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=8C=BA(=E6=96=B9=E4=BE=BF=20Excel=20?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=A4=8D=E5=88=B6=E7=B2=98=E8=B4=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chrome_manager.py | 119 +++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 75 deletions(-) diff --git a/chrome_manager.py b/chrome_manager.py index 98ffa7e..ce611a3 100644 --- a/chrome_manager.py +++ b/chrome_manager.py @@ -122,26 +122,17 @@ def __init__(self): except Exception as e: print(f"设置图标失败: {str(e)}") - # 设置更大的窗口大小,以适应不同DPI设置和字体大小 - self.window_width = 740 - self.window_height = 400 + # 设置固定的窗口大小 + self.window_width = 700 + self.window_height = 360 self.root.geometry(f"{self.window_width}x{self.window_height}") - # 允许窗口调整大小,以适应不同显示设置 - self.root.resizable(True, True) - # 设置最小窗口尺寸,避免过小导致组件显示不全 - self.root.minsize(700, 360) + self.root.resizable(False, False) - # 添加DPI感知支持,确保在高分辨率显示器上显示正常 - try: - from ctypes import windll - # 启用Per-Monitor DPI感知 - windll.shcore.SetProcessDpiAwareness(2) # PROCESS_PER_MONITOR_DPI_AWARE - except Exception as e: - print(f"设置DPI感知失败: {str(e)}") - - # 设置样式 - self.create_styles() + # 设置关闭事件处理 + self.root.protocol("WM_DELETE_WINDOW", self.on_closing) + # 加载主题 + sv_ttk.set_theme("light") print(f"[{time.time() - self.start_time:.3f}s] 主题加载完成") # 仅保存/加载窗口位置,不包括大小 @@ -204,11 +195,14 @@ def __init__(self): self.last_move_time = 0 self.move_interval = 0.016 - # 设置关闭事件处理 - self.root.protocol("WM_DELETE_WINDOW", self.on_closing) + # 创建样式 + self.create_styles() # 创建界面 - self.create_widgets() + self.create_widgets() + + # 更新树形视图样式 + self.update_treeview_style() # 窗口尺寸已在初始化时固定,无需再次调整 @@ -288,9 +282,6 @@ def __init__(self): print(f"[{time.time() - self.start_time:.3f}s] __init__ 完成, 已安排延迟初始化") def create_styles(self): - # 加载主题 - sv_ttk.set_theme("light") - style = ttk.Style() default_font = ('Microsoft YaHei UI', 9) @@ -308,18 +299,19 @@ def create_styles(self): style.configure('TLabelframe.Label', font=default_font) style.configure('TNotebook.Tab', font=default_font) - if self.window_list: - self.window_list.tag_configure("master", - background="#0d6efd", - foreground='white' - ) - # 链接样式 style.configure('Link.TLabel', foreground='#0d6efd', cursor='hand2', font=('Microsoft YaHei UI', 9, 'underline') ) + + def update_treeview_style(self): + """更新Treeview组件的样式,此方法应在window_list初始化后调用""" + if self.window_list: + self.window_list.tag_configure("master", + background="#0d6efd", + foreground="white") def create_widgets(self): """创建界面元素""" @@ -341,23 +333,17 @@ def create_widgets(self): # 第一行:基本操作按钮 first_row = ttk.Frame(button_rows) - first_row.pack(fill=tk.X, expand=True) - - button_frame_left = ttk.Frame(first_row) - button_frame_left.pack(side=tk.LEFT, fill=tk.X, expand=True) + first_row.pack(fill=tk.X) - button_frame_right = ttk.Frame(first_row) - button_frame_right.pack(side=tk.RIGHT, fill=tk.X) - - ttk.Button(button_frame_left, text="导入窗口", command=self.import_windows, style='Accent.TButton').pack(side=tk.LEFT, padx=2) - select_all_label = ttk.Label(button_frame_left, textvariable=self.select_all_var, style='Link.TLabel') + ttk.Button(first_row, text="导入窗口", command=self.import_windows, style='Accent.TButton').pack(side=tk.LEFT, padx=2) + select_all_label = ttk.Label(first_row, textvariable=self.select_all_var, style='Link.TLabel') select_all_label.pack(side=tk.LEFT, padx=5) select_all_label.bind('', self.toggle_select_all) - ttk.Button(button_frame_left, text="自动排列", command=self.auto_arrange_windows).pack(side=tk.LEFT, padx=2) - ttk.Button(button_frame_left, text="关闭选中", command=self.close_selected_windows).pack(side=tk.LEFT, padx=2) + ttk.Button(first_row, text="自动排列", command=self.auto_arrange_windows).pack(side=tk.LEFT, padx=2) + ttk.Button(first_row, text="关闭选中", command=self.close_selected_windows).pack(side=tk.LEFT, padx=2) self.sync_button = ttk.Button( - button_frame_right, + first_row, text="▶ 开始同步", command=self.toggle_sync, style='Accent.TButton' @@ -366,7 +352,7 @@ def create_widgets(self): # 添加设置按钮 ttk.Button( - button_frame_right, + first_row, text="🔗 设置", command=self.show_settings_dialog, width=8 @@ -390,10 +376,10 @@ def create_widgets(self): self.window_list.heading("master", text="主控") self.window_list.heading("hwnd", text="") - self.window_list.column("select", width=50, anchor="center", minwidth=40) - self.window_list.column("number", width=70, anchor="center", minwidth=60) - self.window_list.column("title", width=290, minwidth=200, stretch=True) # 允许标题列伸缩 - self.window_list.column("master", width=60, anchor="center", minwidth=50) + self.window_list.column("select", width=50, anchor="center") + self.window_list.column("number", width=60, anchor="center") + self.window_list.column("title", width=260) + self.window_list.column("master", width=50, anchor="center") self.window_list.column("hwnd", width=0, stretch=False) # 隐藏hwnd列 self.window_list.tag_configure("master", background="lightblue") @@ -2564,7 +2550,7 @@ def batch_open_urls(self): return # 确保 URL 格式正确 - if not url.startswith(('http://', 'https://')): + if not url.startswith(('http://', 'https://', 'chrome-extension://', 'chrome://')): url = 'https://' + url # 获取选中的窗口 @@ -4807,7 +4793,7 @@ def browse_file(): text="开始输入", command=lambda: self.execute_text_input( dialog, - file_path_var.get(), + preview, input_method.get(), overwrite_var.get(), False # 永远不使用延迟输入 @@ -4816,23 +4802,23 @@ def browse_file(): width=10 ).pack(side=tk.RIGHT, padx=5) - def execute_text_input(self, dialog, file_path, input_method, overwrite, delayed): + def execute_text_input(self, dialog, preview, input_method, overwrite, delayed): """执行文本输入操作""" - if not file_path: - messagebox.showwarning("警告", "请选择文本文件!") - return - - if not os.path.exists(file_path): - messagebox.showerror("错误", "文件不存在!") + + # 从预览区获取内容 + preview_content = preview.get('1.0', tk.END).strip() + if not preview_content: + messagebox.showwarning("警告", "预览区内容为空!") return - + lines = [line for line in preview_content.splitlines() if line.strip()] + # 关闭对话框 dialog.destroy() # 调用文本输入功能 - self.input_text_from_file(file_path, input_method, overwrite, delayed) + self.input_text_from_preview(lines, input_method, overwrite, delayed) - def input_text_from_file(self, file_path, input_method, overwrite, delayed): + def input_text_from_preview(self, lines, input_method, overwrite, delayed): """从文件输入文本到选中的窗口""" try: # 获取选中的窗口 @@ -4846,23 +4832,6 @@ def input_text_from_file(self, file_path, input_method, overwrite, delayed): messagebox.showwarning("警告", "请先选择要操作的窗口!") return - # 读取文本文件 - try: - with open(file_path, 'r', encoding='utf-8') as f: - lines = [line.strip() for line in f.readlines() if line.strip()] - except UnicodeDecodeError: - # 尝试其它编码 - try: - with open(file_path, 'r', encoding='gbk') as f: - lines = [line.strip() for line in f.readlines() if line.strip()] - except Exception as e: - messagebox.showerror("错误", f"读取文件失败: {str(e)}") - return - - if not lines: - messagebox.showwarning("警告", "文本文件为空!") - return - # 准备文本行 if input_method == "random": # 为每个窗口随机选择一行