mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-23 14:19:37 +08:00
Add a crash handler to catch uncaught exceptions
This should catch any uncaught exceptions and avoid the Py2Exe message about Cura.log Fixes #133
This commit is contained in:
parent
fb7b7ca7b8
commit
8130bae4c0
41
cura/CrashHandler.py
Normal file
41
cura/CrashHandler.py
Normal file
@ -0,0 +1,41 @@
|
||||
import sys
|
||||
import platform
|
||||
import traceback
|
||||
import webbrowser
|
||||
|
||||
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
|
||||
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit
|
||||
|
||||
def show():
|
||||
dialog = QDialog()
|
||||
dialog.setWindowTitle("Oops!")
|
||||
|
||||
layout = QVBoxLayout(dialog)
|
||||
|
||||
label = QLabel(dialog)
|
||||
layout.addWidget(label)
|
||||
label.setText("<p>An uncaught exception has occurred!</p><p>Please use the information below to post a bug report at <a href=\"http://github.com/Ultimaker/Cura/issues\">http://github.com/Ultimaker/Cura/issues</a></p>")
|
||||
|
||||
textarea = QTextEdit(dialog)
|
||||
layout.addWidget(textarea)
|
||||
|
||||
try:
|
||||
from UM.Application import Application
|
||||
version = Application.getInstance().getVersion()
|
||||
except:
|
||||
version = "Unknown"
|
||||
|
||||
trace = "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
|
||||
|
||||
crash_info = "Version: {0}\nPlatform: {1}\nQt: {2}\nPyQt: {3}\n\nException:\n{4}"
|
||||
crash_info = crash_info.format(version, platform.platform(), QT_VERSION_STR, PYQT_VERSION_STR, trace)
|
||||
|
||||
textarea.setText(crash_info)
|
||||
|
||||
buttons = QDialogButtonBox(QDialogButtonBox.Close, dialog)
|
||||
layout.addWidget(buttons)
|
||||
buttons.addButton("Open Web Page", QDialogButtonBox.HelpRole)
|
||||
buttons.rejected.connect(lambda: dialog.close())
|
||||
buttons.helpRequested.connect(lambda: webbrowser.open("http://github.com/Ultimaker/Cura/issues"))
|
||||
|
||||
dialog.exec_()
|
@ -3,7 +3,12 @@
|
||||
# Copyright (c) 2015 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
try:
|
||||
import cura.CuraApplication
|
||||
|
||||
app = cura.CuraApplication.CuraApplication.getInstance()
|
||||
app.run()
|
||||
except Exception as e:
|
||||
import cura.CrashHandler
|
||||
cura.CrashHandler.show()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user