From e3767696271ac15f2d980defc24c156668fdea6e Mon Sep 17 00:00:00 2001 From: Kevin Wong Date: Thu, 15 Jan 2026 15:06:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E6=88=90=E8=8B=B1=E6=96=87=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- path_gui.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/path_gui.py b/path_gui.py index 744c973..5d294f7 100644 --- a/path_gui.py +++ b/path_gui.py @@ -5,36 +5,37 @@ import threading import os def main(page: ft.Page): - # --- 1. 强制窗口尺寸与初始化 --- + # --- 1. Window Configuration --- page.title = "PathWarp" page.theme_mode = ft.ThemeMode.DARK - page.window.width = 320 # 宽度进一步压缩 - page.window.height = 360 # 高度大幅压缩 - page.window.resizable = False # 禁止缩放,保持精致 - page.window.always_on_top = True # 既然是工具,建议悬浮在最前 + page.window.width = 320 + page.window.height = 360 + page.window.resizable = False + page.window.always_on_top = True page.padding = 10 page.spacing = 10 - # 窗口居中启动 + # Center the window on startup page.window.center() - # 设置图标 + # Set Window Icon if os.path.exists("logo.ico"): page.window.icon = "logo.ico" - # --- 2. 核心转换逻辑 --- + # --- 2. Path Conversion Logic --- def do_convert(win_path): if not win_path: return None p = win_path.strip().strip('"').strip("'") if p.lower().startswith("w:"): rel = p[2:].lstrip("\\") + # Your Samba mapping: W:\ -> /home/rongye/ProgramFiles/ return f"/home/rongye/ProgramFiles/{rel.replace('\\', '/')}" return None - # --- 3. 精简 UI 组件 --- + # --- 3. UI Components --- input_field = ft.TextField( - label="Windows 路径", - hint_text=r"W:\...", + label="Windows Path", + hint_text=r"e.g. W:\Project\Main", text_size=12, height=45, border_color=ft.Colors.CYAN_800, @@ -43,7 +44,7 @@ def main(page: ft.Page): ) result_field = ft.TextField( - label="Ubuntu 路径", + label="Ubuntu Path", read_only=True, text_size=12, height=45, @@ -63,11 +64,11 @@ def main(page: ft.Page): status_text.value = f"Copied: {time.strftime('%H:%M:%S')}" status_text.color = ft.Colors.GREEN_400 else: - status_text.value = "Invalid Path" + status_text.value = "Error: Invalid Path" status_text.color = ft.Colors.RED_400 page.update() - # --- 4. 后台监听 --- + # --- 4. Background Clipboard Monitor --- stop_listen = threading.Event() def listen_clip(): last_clip = "" @@ -91,13 +92,15 @@ def main(page: ft.Page): if listen_switch.value: stop_listen.clear() threading.Thread(target=listen_clip, daemon=True).start() + status_text.value = "Monitoring..." else: stop_listen.set() + status_text.value = "Stopped" page.update() - listen_switch = ft.Switch(label="自动捕获", value=False, on_change=toggle_listen, scale=0.7) + listen_switch = ft.Switch(label="Auto Monitor", value=False, on_change=toggle_listen, scale=0.7) - # --- 5. 极致紧凑布局 --- + # --- 5. Compact Layout --- page.add( ft.Column([ ft.Row([ @@ -108,7 +111,7 @@ def main(page: ft.Page): input_field, ft.FilledButton( - "立即转换", + "Convert & Copy", on_click=convert_click, width=320, height=40,