Skip to content

Commit

Permalink
版本v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Polaris-F committed Aug 29, 2024
1 parent 8cb73c8 commit 86e6ba1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
14 changes: 12 additions & 2 deletions CopyReplace/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import platform
import subprocess
import pyperclip
import time
import configparser
Expand Down Expand Up @@ -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__":
# 启动剪贴板监控线程
Expand Down
51 changes: 51 additions & 0 deletions CopyReplace/main_v2.py
Original file line number Diff line number Diff line change
@@ -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'(?<!#)(zotero://[^\s]+)'
pre_past = ""

while True:
string = pyperclip.paste()
if pre_past != string:
if re.match(".*"+pattern, string):
string = re.sub(pattern, repl, string)
pyperclip.copy(string)
notification.title = ""
notification.message = "替换完毕"
notification.send()

pre_past = string
time.sleep(0.5)

def quit(icon: pystray._win32.Icon) -> 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)
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@


## 介绍



## 手动编译方法
```bash
cd path/to/Link2Zotero
pyinstaller --onefile --icon=Link2Zotero_2.ico --noconsole .\CopyReplace\main.py
```

2 changes: 1 addition & 1 deletion dist/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 86e6ba1

Please sign in to comment.