2023-11-08 00:13:12 +08:00
|
|
|
|
import ctypes
|
2023-01-11 13:04:19 +08:00
|
|
|
|
import sys
|
2023-11-07 22:36:52 +08:00
|
|
|
|
import time
|
2023-12-13 21:35:13 +08:00
|
|
|
|
import traceback
|
2024-05-10 19:13:38 +08:00
|
|
|
|
from PyQt5.QtGui import QFont, QPixmap, QIcon
|
|
|
|
|
from PyQt5.QtWidgets import *
|
|
|
|
|
from PyQt5.QtCore import Qt
|
2023-03-31 11:15:44 +08:00
|
|
|
|
|
2024-02-17 22:21:31 +08:00
|
|
|
|
from app.log.exception_handling import ExceptionHanding, send_error_msg
|
2024-01-21 22:24:17 +08:00
|
|
|
|
from app.ui.Icon import Icon
|
2024-05-10 19:13:38 +08:00
|
|
|
|
from app.DataBase import close_db
|
|
|
|
|
from app.log import logger
|
|
|
|
|
from app.ui import mainview
|
|
|
|
|
from app.ui.tool.pc_decrypt import pc_decrypt
|
|
|
|
|
from app.config import version, SEND_LOG_FLAG
|
2024-01-21 22:24:17 +08:00
|
|
|
|
|
2024-01-02 23:11:29 +08:00
|
|
|
|
widget = None
|
2024-01-03 20:40:04 +08:00
|
|
|
|
|
|
|
|
|
|
2024-01-02 23:11:29 +08:00
|
|
|
|
def excepthook(exc_type, exc_value, traceback_):
|
|
|
|
|
# 将异常信息转为字符串
|
2023-12-20 22:23:13 +08:00
|
|
|
|
|
2024-01-02 23:11:29 +08:00
|
|
|
|
# 在这里处理全局异常
|
2023-01-11 13:04:19 +08:00
|
|
|
|
|
2024-02-08 21:18:27 +08:00
|
|
|
|
error_message = ExceptionHanding(exc_type, exc_value, traceback_)
|
2024-01-21 22:24:17 +08:00
|
|
|
|
txt = '您可添加QQ群发送log文件以便解决该问题'
|
|
|
|
|
msg = f"Exception Type: {exc_type.__name__}\nException Value: {exc_value}\ndetails: {error_message}\n\n{txt}"
|
2024-02-17 22:21:31 +08:00
|
|
|
|
if SEND_LOG_FLAG:
|
|
|
|
|
send_error_msg(msg)
|
2024-01-02 23:11:29 +08:00
|
|
|
|
logger.error(f'程序发生了错误:\n\n{msg}')
|
2024-01-21 22:24:17 +08:00
|
|
|
|
# 创建一个 QMessageBox 对象
|
|
|
|
|
error_box = QMessageBox()
|
|
|
|
|
|
|
|
|
|
# 设置对话框的标题
|
|
|
|
|
error_box.setWindowTitle("未知错误")
|
|
|
|
|
pixmap = QPixmap(Icon.logo_ico_path)
|
|
|
|
|
icon = QIcon(pixmap)
|
|
|
|
|
error_box.setWindowIcon(icon)
|
|
|
|
|
# 设置对话框的文本消息
|
|
|
|
|
error_box.setText(msg)
|
|
|
|
|
# 设置对话框的图标,使用 QMessageBox.Critical 作为图标类型
|
|
|
|
|
error_box.setIcon(QMessageBox.Critical)
|
|
|
|
|
# 添加一个“确定”按钮
|
|
|
|
|
error_box.addButton(QMessageBox.Ok)
|
2024-03-02 20:08:04 +08:00
|
|
|
|
|
2024-01-21 22:24:17 +08:00
|
|
|
|
# 显示对话框
|
|
|
|
|
error_box.exec_()
|
2024-01-02 23:11:29 +08:00
|
|
|
|
|
|
|
|
|
# 调用原始的 excepthook,以便程序正常退出
|
|
|
|
|
sys.__excepthook__(exc_type, exc_value, traceback_)
|
|
|
|
|
|
2024-01-03 20:40:04 +08:00
|
|
|
|
|
2024-01-02 23:11:29 +08:00
|
|
|
|
# 设置 excepthook
|
|
|
|
|
sys.excepthook = excepthook
|
2024-01-07 20:24:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("WeChatReport")
|
|
|
|
|
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
|
|
|
|
|
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
|
2024-01-03 20:40:04 +08:00
|
|
|
|
|
|
|
|
|
|
2023-12-13 21:35:13 +08:00
|
|
|
|
class ViewController(QWidget):
|
2023-04-02 21:23:20 +08:00
|
|
|
|
def __init__(self):
|
2023-12-13 21:35:13 +08:00
|
|
|
|
super().__init__()
|
|
|
|
|
self.viewMainWindow = None
|
2023-04-02 21:23:20 +08:00
|
|
|
|
self.viewDecrypt = None
|
|
|
|
|
|
2023-11-12 21:51:33 +08:00
|
|
|
|
def loadPCDecryptView(self):
|
2023-01-11 13:04:19 +08:00
|
|
|
|
"""
|
2023-11-12 21:51:33 +08:00
|
|
|
|
登录界面
|
2023-01-11 13:04:19 +08:00
|
|
|
|
:return:
|
|
|
|
|
"""
|
2023-11-12 21:51:33 +08:00
|
|
|
|
self.viewDecrypt = pc_decrypt.DecryptControl()
|
2023-12-13 21:35:13 +08:00
|
|
|
|
self.viewDecrypt.DecryptSignal.connect(self.show_success)
|
2023-11-12 21:51:33 +08:00
|
|
|
|
self.viewDecrypt.show()
|
2023-01-11 13:04:19 +08:00
|
|
|
|
|
2023-10-29 23:15:46 +08:00
|
|
|
|
def loadMainWinView(self, username=None):
|
2023-01-11 13:04:19 +08:00
|
|
|
|
"""
|
|
|
|
|
聊天界面
|
|
|
|
|
:param username: 账号
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
username = ''
|
2023-11-07 22:36:52 +08:00
|
|
|
|
start = time.time()
|
2023-12-13 21:35:13 +08:00
|
|
|
|
self.viewMainWindow = mainview.MainWinController(username=username)
|
|
|
|
|
self.viewMainWindow.exitSignal.connect(self.close)
|
|
|
|
|
try:
|
|
|
|
|
self.viewMainWindow.setWindowTitle(f"留痕-{version}")
|
|
|
|
|
self.viewMainWindow.show()
|
|
|
|
|
end = time.time()
|
|
|
|
|
self.viewMainWindow.init_ui()
|
2024-01-05 21:13:54 +08:00
|
|
|
|
print('ok', '本次加载用了', end - start, 's')
|
|
|
|
|
|
2023-12-13 21:35:13 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"Exception: {e}")
|
2024-01-17 21:49:47 +08:00
|
|
|
|
logger.error(traceback.format_exc())
|
2023-12-13 21:35:13 +08:00
|
|
|
|
|
|
|
|
|
def show_success(self):
|
|
|
|
|
QMessageBox.about(self, "解密成功", "数据库文件存储在\napp/DataBase/Msg\n文件夹下")
|
2023-01-11 13:04:19 +08:00
|
|
|
|
|
2023-12-16 20:06:43 +08:00
|
|
|
|
def close(self) -> bool:
|
|
|
|
|
close_db()
|
|
|
|
|
super().close()
|
2023-12-20 22:23:13 +08:00
|
|
|
|
|
|
|
|
|
|
2023-01-11 13:04:19 +08:00
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
app = QApplication(sys.argv)
|
2023-12-14 22:59:48 +08:00
|
|
|
|
font = QFont('微软雅黑', 12) # 使用 Times New Roman 字体,字体大小为 14
|
|
|
|
|
app.setFont(font)
|
2023-01-11 13:04:19 +08:00
|
|
|
|
view = ViewController()
|
2024-01-03 20:40:04 +08:00
|
|
|
|
widget = view.viewMainWindow
|
2023-12-13 21:35:13 +08:00
|
|
|
|
try:
|
|
|
|
|
# view.loadPCDecryptView()
|
|
|
|
|
view.loadMainWinView()
|
|
|
|
|
# view.show()
|
|
|
|
|
# view.show_success()
|
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"Exception: {e}")
|
2024-01-18 10:25:07 +08:00
|
|
|
|
logger.error(traceback.format_exc())
|