Error reporting dialog can (finally) upload error reports to Pastebin.

This commit is contained in:
David Vierra 2015-09-17 20:40:32 -10:00
parent e11787a4fa
commit 39a113dab9
3 changed files with 69 additions and 4 deletions

View File

@ -8,3 +8,4 @@ pygments
pyzmq pyzmq
numpy>=1.9.0, <1.10.0 numpy>=1.9.0, <1.10.0
arrow arrow
pastebin

View File

@ -7,26 +7,31 @@ import traceback
import sys import sys
import platform import platform
from PySide import QtGui from PySide import QtGui, QtCore
from mcedit2.util import qglcontext from mcedit2.util import qglcontext
from mcedit2.util.load_ui import load_ui from mcedit2.util.load_ui import load_ui
from mcedit2.util.screen import centerWidgetInScreen
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def showErrorDialog(text, tb, fatal): def showErrorDialog(text, tb, fatal):
dialog = ErrorDialog(text, tb, fatal) dialog = ErrorDialog(text, tb, fatal)
dialog.exec_() dialog.exec_()
class ErrorDialog(QtGui.QDialog): class ErrorDialog(QtGui.QDialog):
""" """
A dialog for displaying an error traceback when something goes wrong. A dialog for displaying an error traceback when something goes wrong.
Used to report compile and run errors for plugin modules and classes, and might be Used to report compile and run errors for plugin modules and classes, and
used to report errors in MCEdit itself during signal or event handlers. to report errors in MCEdit itself during signal or event handlers.
""" """
def __init__(self, text, exc_info, fatal): def __init__(self, text, exc_info, fatal):
super(ErrorDialog, self).__init__() super(ErrorDialog, self).__init__()
self.setModal(True)
load_ui("error_dialog.ui", baseinstance=self) load_ui("error_dialog.ui", baseinstance=self)
exc_type, exc_value, exc_tb = exc_info exc_type, exc_value, exc_tb = exc_info
@ -49,7 +54,52 @@ class ErrorDialog(QtGui.QDialog):
"%s" % (__version__, sys.version, sys.platform, "%s" % (__version__, sys.version, sys.platform,
platform.platform(), platform.processor(), platform.platform(), platform.processor(),
contextInfo, text, tbText) contextInfo, text, tbText)
self.errorText = tbText
self.tracebackView.setText(tbText) self.tracebackView.setText(tbText)
self.restartMCEditLabel.setVisible(fatal) self.restartMCEditLabel.setVisible(fatal)
self.restartMCEditButton.setVisible(False)
self.restartMCEditButton.setEnabled(False) # xxxx connect me
try:
import Pastebin
except ImportError:
self.copyToPastebinButton.setVisible(False)
else:
self.copyToPastebinButton.setVisible(True)
self.copyToPastebinButton.clicked.connect(self.copyToPastebin)
self.pastebinURLBox.setVisible(False)
def show(self, *args, **kwargs):
super(ErrorDialog, self).show(*args, **kwargs)
centerWidgetInScreen(self)
def copyToPastebin(self):
import Pastebin
api_dev_key = '0a9ae46e71b44c10184212e4674912c5'
url = None
progressText = self.tr("Uploading to pastebin...")
dialog = QtGui.QProgressDialog(progressText,
None, 0, 0, self)
dialog.setLabelText(progressText)
dialog.setWindowTitle(progressText)
dialog.setStatusTip(progressText)
dialog.show()
QtGui.qApp.processEvents()
try:
url = Pastebin.paste(api_dev_key, self.errorText,
paste_expire_date="1M")
except Exception as e:
log.warn("Failed to upload to pastebin!", exc_info=1)
self.copyToPastebinLabel.setText(self.tr("Failed to upload to pastebin: ") + str(e))
finally:
dialog.hide()
if url:
self.pastebinURLBox.setVisible(True)
self.pastebinURLBox.setText(url)
QtGui.QApplication.clipboard().setText(url)
self.copyToPastebinLabel.setText(self.tr("Pastebin URL copied to clipboard!"))

View File

@ -72,12 +72,19 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="copyToPastebinLabel">
<property name="text"> <property name="text">
<string>Clicking &quot;Copy to PasteBin&quot; will copy a Pastebin URL to your clipboard.</string> <string>Clicking &quot;Copy to PasteBin&quot; will copy a Pastebin URL to your clipboard.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLineEdit" name="pastebinURLBox">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
@ -100,6 +107,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="restartMCEditButton">
<property name="text">
<string>Restart MCEdit</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="continueButton"> <widget class="QPushButton" name="continueButton">
<property name="text"> <property name="text">