refactor: migrate GUI from tkinter to PyQt5

主要改动:

1. GUI框架迁移 - 从 tkinter 完全迁移到 PyQt5 - 重写了所有界面组件和布局 - 优化了界面交互逻辑

2. 界面改进 - 使用 QMainWindow 作为主窗口 - 采用 QVBoxLayout 和 QHBoxLayout 进行布局 - 使用 QFrame 组织界面结构 - 添加了状态显示区域的滚动功能

3. 功能优化 - 改进了错误处理和消息显示 - 使用 QMessageBox 替代 tkinter messagebox - 添加了剪贴板操作功能 - 优化了状态更新逻辑

4. 性能提升 - 移除了不必要的窗口刷新 - 使用 QTimer 优化状态检查 - 简化了窗口管理逻辑

5. 代码质量 - 改进了代码组织结构 - 增强了错误处理 - 添加了详细的日志记录 - 优化了资源管理

6. 依赖管理 - 更新了 PyInstaller spec 文件 - 添加了必要的 PyQt5 依赖 - 确保打包后的程序正常运行
This commit is contained in:
huangzhenpc
2025-02-12 13:33:11 +08:00
parent 6281f86743
commit c58903846d
3 changed files with 118 additions and 246 deletions

34
main.py
View File

@@ -1,9 +1,29 @@
import logging
import sys
import traceback
import os
import atexit
import shutil
import tempfile
from pathlib import Path
from PyQt5.QtWidgets import QApplication, QMessageBox
from gui.main_window import MainWindow
def cleanup_temp():
"""清理临时文件"""
try:
temp_dir = Path(tempfile._get_default_tempdir())
for item in temp_dir.glob('_MEI*'):
try:
if item.is_dir():
shutil.rmtree(str(item), ignore_errors=True)
elif item.is_file():
item.unlink()
except:
pass
except:
pass
def setup_logging():
"""设置日志"""
try:
@@ -27,6 +47,9 @@ def setup_logging():
def main():
"""主函数"""
try:
# 注册退出时的清理函数
atexit.register(cleanup_temp)
setup_logging()
# 检查Python版本
@@ -41,17 +64,20 @@ def main():
logging.info(f" - {p}")
logging.info("正在初始化主窗口...")
app = QApplication(sys.argv)
window = MainWindow()
logging.info("正在启动主窗口...")
window.run()
window.show()
sys.exit(app.exec_())
except Exception as e:
error_msg = f"程序运行出错: {str(e)}\n{traceback.format_exc()}"
logging.error(error_msg)
# 使用tkinter的消息框显示错误
from tkinter import messagebox
messagebox.showerror("错误", error_msg)
# 使用 QMessageBox 显示错误
app = QApplication(sys.argv)
QMessageBox.critical(None, "错误", error_msg)
sys.exit(1)
if __name__ == "__main__":
main()