Handle --debug specially

This commit is contained in:
Florian Bruhin 2014-10-31 07:05:04 +01:00
parent da0f433260
commit a2809e76bb
2 changed files with 29 additions and 18 deletions

View File

@ -188,7 +188,7 @@ class Application(QApplication):
if data: if data:
# Crashlog exists and has data in it, so something crashed # Crashlog exists and has data in it, so something crashed
# previously. # previously.
self._crashdlg = crash.FatalCrashDialog(data) self._crashdlg = crash.FatalCrashDialog(self._args.debug, data)
self._crashdlg.show() self._crashdlg.show()
else: else:
# There's no log file, so we can use this to display crashes to the # There's no log file, so we can use this to display crashes to the
@ -485,8 +485,8 @@ class Application(QApplication):
except TypeError: except TypeError:
log.destroy.exception("Error while preventing shutdown") log.destroy.exception("Error while preventing shutdown")
QApplication.closeAllWindows() QApplication.closeAllWindows()
self._crashdlg = crash.ExceptionCrashDialog(pages, history, exc, self._crashdlg = crash.ExceptionCrashDialog(
objects) self._args.debug, pages, history, exc, objects)
ret = self._crashdlg.exec_() ret = self._crashdlg.exec_()
if ret == QDialog.Accepted: # restore if ret == QDialog.Accepted: # restore
self.restart(shutdown=False, pages=pages) self.restart(shutdown=False, pages=pages)

View File

@ -48,8 +48,12 @@ class _CrashDialog(QDialog):
_crash_info: A list of tuples with title and crash information. _crash_info: A list of tuples with title and crash information.
""" """
def __init__(self, parent=None): def __init__(self, debug, parent=None):
"""Constructor for CrashDialog.""" """Constructor for CrashDialog.
Args:
debug: Whether --debug was given.
"""
super().__init__(parent) super().__init__(parent)
# We don't set WA_DeleteOnClose here as on an exception, we'll get # We don't set WA_DeleteOnClose here as on an exception, we'll get
# closed anyways, and it only could have unintended side-effects. # closed anyways, and it only could have unintended side-effects.
@ -78,19 +82,21 @@ class _CrashDialog(QDialog):
self._vbox.addSpacing(15) self._vbox.addSpacing(15)
self._debug_log = QTextEdit(tabChangesFocus=True) self._debug_log = QTextEdit(tabChangesFocus=True)
self._debug_log.hide()
info = QLabel("<i>You can edit the log below to remove sensitive " info = QLabel("<i>You can edit the log below to remove sensitive "
"information.</i>", wordWrap=True) "information.</i>", wordWrap=True)
info.hide() info.hide()
self._fold = DetailFold("Show log", self) self._fold = DetailFold("Show log", self)
self._fold.toggled.connect(self._debug_log.setVisible) self._fold.toggled.connect(self._debug_log.setVisible)
self._fold.toggled.connect(info.setVisible) self._fold.toggled.connect(info.setVisible)
if debug:
self._fold.toggle()
self._vbox.addWidget(self._fold) self._vbox.addWidget(self._fold)
self._vbox.addWidget(info) self._vbox.addWidget(info)
self._vbox.addWidget(self._debug_log, 10) self._vbox.addWidget(self._debug_log, 10)
self._debug_log.hide()
self._vbox.addSpacing(15) self._vbox.addSpacing(15)
self._init_checkboxes() self._init_checkboxes(debug)
self._init_buttons() self._init_buttons()
def __repr__(self): def __repr__(self):
@ -104,13 +110,15 @@ class _CrashDialog(QDialog):
self._lbl.setWordWrap(True) self._lbl.setWordWrap(True)
self._vbox.addWidget(self._lbl) self._vbox.addWidget(self._lbl)
def _init_checkboxes(self): def _init_checkboxes(self, debug):
"""Initialize the checkboxes. """Initialize the checkboxes.
Should be overwritten by subclasses. Args:
debug: Whether a --debug arg was given.
""" """
self._chk_report = QCheckBox("Send a report") self._chk_report = QCheckBox("Send a report")
self._chk_report.setChecked(True) if not debug:
self._chk_report.setChecked(True)
self._vbox.addWidget(self._chk_report) self._vbox.addWidget(self._chk_report)
info_label = QLabel("<i>Note that without your help, I can't fix the " info_label = QLabel("<i>Note that without your help, I can't fix the "
"bug you encountered.</i>", wordWrap=True) "bug you encountered.</i>", wordWrap=True)
@ -204,8 +212,8 @@ class ExceptionCrashDialog(_CrashDialog):
_objects: A list of all QObjects as string. _objects: A list of all QObjects as string.
""" """
def __init__(self, pages, cmdhist, exc, objects, parent=None): def __init__(self, debug, pages, cmdhist, exc, objects, parent=None):
super().__init__(parent) super().__init__(debug, parent)
self._pages = pages self._pages = pages
self._cmdhist = cmdhist self._cmdhist = cmdhist
self._exc = exc self._exc = exc
@ -232,11 +240,14 @@ class ExceptionCrashDialog(_CrashDialog):
self._buttons = [btn_quit, btn_restart] self._buttons = [btn_quit, btn_restart]
def _init_checkboxes(self): def _init_checkboxes(self, debug):
"""Add checkboxes to send crash report.""" """Add checkboxes to send crash report."""
super()._init_checkboxes() super()._init_checkboxes(debug)
self._chk_log = QCheckBox("Include a debug log and a list of open " self._chk_log = QCheckBox("Include a debug log and a list of open "
"pages", checked=True) "pages", checked=True)
if debug:
self._chk_log.setChecked(False)
self._chk_log.setEnabled(False)
self._chk_log.toggled.connect(self._set_crash_info) self._chk_log.toggled.connect(self._set_crash_info)
self._vbox.addWidget(self._chk_log) self._vbox.addWidget(self._chk_log)
info_label = QLabel("<i>This makes it a lot easier to diagnose the " info_label = QLabel("<i>This makes it a lot easier to diagnose the "
@ -281,8 +292,8 @@ class FatalCrashDialog(_CrashDialog):
_log: The log text to display. _log: The log text to display.
""" """
def __init__(self, text, parent=None): def __init__(self, debug, text, parent=None):
super().__init__(parent) super().__init__(debug, parent)
self._log = text self._log = text
self.setAttribute(Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_DeleteOnClose)
self._set_crash_info() self._set_crash_info()
@ -318,7 +329,7 @@ class ReportDialog(_CrashDialog):
""" """
def __init__(self, pages, cmdhist, objects, parent=None): def __init__(self, pages, cmdhist, objects, parent=None):
super().__init__(parent) super().__init__(False, parent)
self.setAttribute(Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_DeleteOnClose)
self._btn_report = None self._btn_report = None
self._pages = pages self._pages = pages
@ -338,7 +349,7 @@ class ReportDialog(_CrashDialog):
self._btn_report.clicked.connect(self.close) self._btn_report.clicked.connect(self.close)
self._hbox.addWidget(self._btn_report) self._hbox.addWidget(self._btn_report)
def _init_checkboxes(self): def _init_checkboxes(self, _debug):
"""We don't want any checkboxes as the user wanted to report.""" """We don't want any checkboxes as the user wanted to report."""
pass pass