From e30b6396d2546d3c344ec27f351488469fe02e20 Mon Sep 17 00:00:00 2001 From: shuaikangzhou <863909694@qq.com> Date: Tue, 2 Jan 2024 23:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=85=A8=E5=B1=80=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ui/contact/export_dialog.py | 1 + main.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/ui/contact/export_dialog.py b/app/ui/contact/export_dialog.py index 915608b..81bd3c6 100644 --- a/app/ui/contact/export_dialog.py +++ b/app/ui/contact/export_dialog.py @@ -106,6 +106,7 @@ class ExportDialog(QDialog): def set_total_msg_num(self, num): self.total_msg_num = num + # b''+num +(1,1) def export_finished(self): self.export_button.setEnabled(True) diff --git a/main.py b/main.py index fcd605e..00e739a 100644 --- a/main.py +++ b/main.py @@ -16,8 +16,22 @@ from app.config import version ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("WeChatReport") QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) +widget = None +def excepthook(exc_type, exc_value, traceback_): + # 将异常信息转为字符串 + # 在这里处理全局异常 + error_message = ''.join(traceback.format_exception(exc_type, exc_value, traceback_)) + msg = f"Exception Type: {exc_type.__name__}\nException Value: {exc_value}\ndetails: {error_message}" + logger.error(f'程序发生了错误:\n\n{msg}') + QMessageBox.critical(widget, "Unhandled Exception", msg, QMessageBox.Ok) + + # 调用原始的 excepthook,以便程序正常退出 + sys.__excepthook__(exc_type, exc_value, traceback_) + +# 设置 excepthook +sys.excepthook = excepthook class ViewController(QWidget): def __init__(self): super().__init__() @@ -66,6 +80,7 @@ if __name__ == '__main__': font = QFont('微软雅黑', 12) # 使用 Times New Roman 字体,字体大小为 14 app.setFont(font) view = ViewController() + widget = view try: # view.loadPCDecryptView() view.loadMainWinView()