Disable crash handler if debug mode is not enabled

This commit is contained in:
Arjen Hiemstra 2015-10-05 14:13:49 +02:00
parent a9527920ae
commit 03748ca19a
2 changed files with 14 additions and 5 deletions

View file

@ -5,12 +5,20 @@ import webbrowser
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR, QCoreApplication from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR, QCoreApplication
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit
from UM.Application import Application
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
def show(type, value, tb): debug_mode = False
if not hasattr(sys, "frozen"):
traceback.print_exception(type, value, tb) def show(exception_type, value, tb):
if Application.getInstance().getCommandLineOption("debug-mode", False):
debug_mode = True
traceback.print_exception(exception_type, value, tb)
if not debug_mode:
return
application = QCoreApplication.instance() application = QCoreApplication.instance()
if not application: if not application:
@ -34,7 +42,7 @@ def show(type, value, tb):
except: except:
version = "Unknown" version = "Unknown"
trace = "".join(traceback.format_exception(type, value, tb)) trace = "".join(traceback.format_exception(exception_type, value, tb))
crash_info = "Version: {0}\nPlatform: {1}\nQt: {2}\nPyQt: {3}\n\nException:\n{4}" 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) crash_info = crash_info.format(version, platform.platform(), QT_VERSION_STR, PYQT_VERSION_STR, trace)
@ -44,7 +52,7 @@ def show(type, value, tb):
buttons = QDialogButtonBox(QDialogButtonBox.Close, dialog) buttons = QDialogButtonBox(QDialogButtonBox.Close, dialog)
layout.addWidget(buttons) layout.addWidget(buttons)
buttons.addButton(catalog.i18nc("@action:button", "Open Web Page"), QDialogButtonBox.HelpRole) buttons.addButton(catalog.i18nc("@action:button", "Open Web Page"), QDialogButtonBox.HelpRole)
buttons.rejected.connect(lambda: dialog.close()) buttons.rejected.connect(dialog.close)
buttons.helpRequested.connect(lambda: webbrowser.open("http://github.com/Ultimaker/Cura/issues")) buttons.helpRequested.connect(lambda: webbrowser.open("http://github.com/Ultimaker/Cura/issues"))
dialog.exec_() dialog.exec_()

View file

@ -125,6 +125,7 @@ class CuraApplication(QtApplication):
def addCommandLineOptions(self, parser): def addCommandLineOptions(self, parser):
super().addCommandLineOptions(parser) super().addCommandLineOptions(parser)
parser.add_argument("file", nargs="*", help="Files to load after starting the application.") parser.add_argument("file", nargs="*", help="Files to load after starting the application.")
parser.add_argument("--debug", dest="debug-mode", action="store_true", default=False, help="Enable detailed crash reports.")
def run(self): def run(self):
self._i18n_catalog = i18nCatalog("cura"); self._i18n_catalog = i18nCatalog("cura");