feat: 完成PyQt5 GUI实现,支持系统托盘和图标显示
1. 实现了基于PyQt5的GUI界面 2. 添加系统托盘功能,支持最小化到托盘 3. 修复了图标显示问题,包括窗口图标和任务栏图标 4. 优化了打包配置,支持PyInstaller打包 5. 版本更新到v3.3.1
This commit is contained in:
29
main.py
29
main.py
@@ -6,7 +6,9 @@ import atexit
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from PyQt5.QtWidgets import QApplication, QMessageBox
|
||||
from PyQt5.QtWidgets import QApplication, QMessageBox, QSystemTrayIcon, QMenu
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtCore import Qt
|
||||
from gui.main_window import MainWindow
|
||||
|
||||
def cleanup_temp():
|
||||
@@ -65,7 +67,32 @@ def main():
|
||||
|
||||
logging.info("正在初始化主窗口...")
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
# 设置应用程序ID (在设置图标之前)
|
||||
if sys.platform == "win32":
|
||||
import ctypes
|
||||
myappid = u'nezha.cursor.helper.v3'
|
||||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
|
||||
logging.info(f"设置应用程序ID: {myappid}")
|
||||
|
||||
# 设置应用程序图标
|
||||
try:
|
||||
icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "icon", "two.ico")
|
||||
if os.path.exists(icon_path):
|
||||
app_icon = QIcon(icon_path)
|
||||
if not app_icon.isNull():
|
||||
app.setWindowIcon(app_icon)
|
||||
logging.info(f"成功设置应用程序图标: {icon_path}")
|
||||
else:
|
||||
logging.error("图标文件加载失败")
|
||||
else:
|
||||
logging.error(f"图标文件不存在: {icon_path}")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"设置应用程序图标失败: {str(e)}")
|
||||
|
||||
window = MainWindow()
|
||||
window.setWindowIcon(app.windowIcon()) # 确保窗口使用相同的图标
|
||||
|
||||
logging.info("正在启动主窗口...")
|
||||
window.show()
|
||||
|
||||
Reference in New Issue
Block a user