From 86e6ba15fce21f81d5c0429522993b1cbf758875 Mon Sep 17 00:00:00 2001 From: Polaris Date: Thu, 29 Aug 2024 11:17:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=ACv1.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CopyReplace/main.py | 14 ++++++++++-- CopyReplace/main_v2.py | 51 ++++++++++++++++++++++++++++++++++++++++++ README.md | 9 ++++++++ dist/config.ini | 2 +- 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 CopyReplace/main_v2.py diff --git a/CopyReplace/main.py b/CopyReplace/main.py index c7d747b..73d955d 100644 --- a/CopyReplace/main.py +++ b/CopyReplace/main.py @@ -1,4 +1,5 @@ import platform +import subprocess import pyperclip import time import configparser @@ -76,16 +77,25 @@ def on_quit(icon, item): def on_restart(icon, item): python = sys.executable - os.execl(python, python, *sys.argv) + icon.stop() # 停止托盘图标,释放资源 + + # 添加延时,等待资源释放 + time.sleep(2) # 等待2秒(你可以根据需要调整时间) + + subprocess.Popen([python] + sys.argv) + sys.exit() # 退出当前进程 # 设置系统托盘图标和菜单 def setup_tray_icon(): # 使用本地图片作为托盘图标 - icon = Icon("Link2Zotero", Image.open(icon_path), "Link2Zotero", Menu( + image = Image.open(icon_path) + icon = Icon("Link2Zotero", image, "Link2Zotero", Menu( MenuItem('Restart', on_restart), MenuItem('Quit', on_quit) )) icon.run() + image.close() # 确保图像文件在使用后被关闭 + if __name__ == "__main__": # 启动剪贴板监控线程 diff --git a/CopyReplace/main_v2.py b/CopyReplace/main_v2.py new file mode 100644 index 0000000..d1ce2af --- /dev/null +++ b/CopyReplace/main_v2.py @@ -0,0 +1,51 @@ +import re +import time +import pyperclip +import pystray +from pystray import Icon, Menu, MenuItem +from PIL import Image +import pystray._win32 +import threading +from notifypy import Notify + +def repl(match: re.Match): + return "https://hichennyang.github.io/zotero-link/#{}".format(match.group()) + +def main(): + notification = Notify( + default_notification_application_name = "zotero-link", + default_notification_icon = "Link2Zotero_2.png" + ) + # pattern = r"zotero://\S*\)\)" + pattern = r'(? None: + icon.stop() + +def setup(icon: pystray._win32.Icon) -> None: + icon.visible = True + threading.Thread(target=main, daemon=True).start() + +if __name__ == "__main__": + Icon( + "zotero-link", + icon = Image.open("Link2Zotero_2.png"), + title = "zotero-link", + menu = Menu( + MenuItem("退出", quit) + ) + ).run(setup) diff --git a/README.md b/README.md index 8da502f..dc1880f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ ## 介绍 + + + +## 手动编译方法 +```bash +cd path/to/Link2Zotero +pyinstaller --onefile --icon=Link2Zotero_2.ico --noconsole .\CopyReplace\main.py +``` + diff --git a/dist/config.ini b/dist/config.ini index 34b90a9..4022d34 100644 --- a/dist/config.ini +++ b/dist/config.ini @@ -3,4 +3,4 @@ [Settings] replace_url = "https://flaribbit.github.io/zotero-link/#zotero://" -icon_path = "D:\Github\Tools\Link2Zotero\CopyReplace\Link2Zotero_2.ico" +icon_path = "D:/Github/Tools/Link2Zotero/dist/Link2Zotero_2.ico"