[Add] ExceptionDialog for showing exception message

This commit is contained in:
vn.py 2019-08-07 11:37:15 +08:00
parent b5e9bdb559
commit 1a82f6caf9

View File

@ -2,6 +2,7 @@ import ctypes
import platform import platform
import sys import sys
import traceback import traceback
import webbrowser
import qdarkstyle import qdarkstyle
from PyQt5 import QtGui, QtWidgets, QtCore from PyQt5 import QtGui, QtWidgets, QtCore
@ -19,9 +20,8 @@ def excepthook(exctype, value, tb):
sys.__excepthook__(exctype, value, tb) sys.__excepthook__(exctype, value, tb)
msg = "".join(traceback.format_exception(exctype, value, tb)) msg = "".join(traceback.format_exception(exctype, value, tb))
QtWidgets.QMessageBox.critical( dialog = ExceptionDialog(msg)
None, "Exception", msg, QtWidgets.QMessageBox.Ok dialog.exec_()
)
def create_qapp(app_name: str = "VN Trader"): def create_qapp(app_name: str = "VN Trader"):
@ -45,3 +45,53 @@ def create_qapp(app_name: str = "VN Trader"):
) )
return qapp return qapp
class ExceptionDialog(QtWidgets.QDialog):
""""""
def __init__(self, msg: str):
""""""
super().__init__()
self.msg = msg
self.init_ui()
def init_ui(self):
""""""
self.setWindowTitle("触发异常")
self.setFixedSize(600, 600)
self.msg_edit = QtWidgets.QTextEdit()
self.msg_edit.setText(self.msg)
self.msg_edit.setReadOnly(True)
copy_button = QtWidgets.QPushButton("复制")
copy_button.clicked.connect(self._copy_text)
community_button = QtWidgets.QPushButton("求助")
community_button.clicked.connect(self._open_community)
close_button = QtWidgets.QPushButton("关闭")
close_button.clicked.connect(self.close)
hbox = QtWidgets.QHBoxLayout()
hbox.addWidget(copy_button)
hbox.addWidget(community_button)
hbox.addWidget(close_button)
vbox = QtWidgets.QVBoxLayout()
vbox.addWidget(self.msg_edit)
vbox.addLayout(hbox)
self.setLayout(vbox)
def _copy_text(self):
""""""
self.msg_edit.selectAll()
self.msg_edit.copy()
def _open_community(self):
""""""
webbrowser.open("https://www.vnpy.com/forum/forum/2-ti-wen-qiu-zhu")