diff --git a/README.md b/README.md index dfeee04..012318b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ -# PathWarp - +## Windows上Samba访问地址切换成Ubuntu实际路径小工具 + +### 安装步骤 + +```bash +python -m venv venv +.\venv\Scripts\activate +pip install -r requirements.txt +python path_gui.py +pyinstaller --noconsole --icon=logo.ico --name="PathWarp" path_gui.py +``` + diff --git a/logo.ico b/logo.ico new file mode 100644 index 0000000..903d5a0 Binary files /dev/null and b/logo.ico differ diff --git a/path_gui.py b/path_gui.py new file mode 100644 index 0000000..744c973 --- /dev/null +++ b/path_gui.py @@ -0,0 +1,130 @@ +import flet as ft +import pyperclip +import time +import threading +import os + +def main(page: ft.Page): + # --- 1. 强制窗口尺寸与初始化 --- + 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.padding = 10 + page.spacing = 10 + + # 窗口居中启动 + page.window.center() + + # 设置图标 + if os.path.exists("logo.ico"): + page.window.icon = "logo.ico" + + # --- 2. 核心转换逻辑 --- + 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("\\") + return f"/home/rongye/ProgramFiles/{rel.replace('\\', '/')}" + return None + + # --- 3. 精简 UI 组件 --- + input_field = ft.TextField( + label="Windows 路径", + hint_text=r"W:\...", + text_size=12, + height=45, + border_color=ft.Colors.CYAN_800, + prefix_icon=ft.Icons.FOLDER_OPEN, + content_padding=10, + ) + + result_field = ft.TextField( + label="Ubuntu 路径", + read_only=True, + text_size=12, + height=45, + color=ft.Colors.GREEN_400, + border_color=ft.Colors.GREEN_900, + prefix_icon=ft.Icons.TERMINAL, + content_padding=10, + ) + + status_text = ft.Text("Ready", size=10, color=ft.Colors.GREY_600) + + def convert_click(e): + res = do_convert(input_field.value) + if res: + result_field.value = res + pyperclip.copy(res) + 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.color = ft.Colors.RED_400 + page.update() + + # --- 4. 后台监听 --- + stop_listen = threading.Event() + def listen_clip(): + last_clip = "" + while not stop_listen.is_set(): + try: + curr = pyperclip.paste().strip().strip('"') + if curr != last_clip and curr.lower().startswith("w:"): + conv = do_convert(curr) + if conv: + pyperclip.copy(conv) + input_field.value = curr + result_field.value = conv + status_text.value = "Auto-Warped" + status_text.color = ft.Colors.CYAN_400 + last_clip = conv + page.update() + except: pass + time.sleep(0.5) + + def toggle_listen(e): + if listen_switch.value: + stop_listen.clear() + threading.Thread(target=listen_clip, daemon=True).start() + else: + stop_listen.set() + page.update() + + listen_switch = ft.Switch(label="自动捕获", value=False, on_change=toggle_listen, scale=0.7) + + # --- 5. 极致紧凑布局 --- + page.add( + ft.Column([ + ft.Row([ + ft.Icon(ft.Icons.BOLT, color=ft.Colors.CYAN_400, size=18), + ft.Text("PathWarp", size=16, weight=ft.FontWeight.BOLD), + ], alignment=ft.MainAxisAlignment.CENTER), + + input_field, + + ft.FilledButton( + "立即转换", + on_click=convert_click, + width=320, + height=40, + style=ft.ButtonStyle(shape=ft.RoundedRectangleBorder(radius=6)), + ), + + result_field, + + ft.Container( + content=ft.Row([listen_switch, status_text], alignment=ft.MainAxisAlignment.SPACE_BETWEEN), + padding=ft.padding.only(left=5, right=10), + bgcolor=ft.Colors.BLACK12, + border_radius=5, + ) + ], spacing=8) + ) + +if __name__ == "__main__": + ft.app(target=main) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dddc817 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +flet>=0.21.0 +pyperclip>=1.8.2 +pyinstaller>=6.3.0 \ No newline at end of file