diff --git a/requirements.txt b/requirements.txt index 1b2fbc9..c16a498 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ pygments pyzmq numpy>=1.9.0, <1.10.0 arrow +pastebin diff --git a/src/mcedit2/dialogs/error_dialog.py b/src/mcedit2/dialogs/error_dialog.py index 956c6a4..28d991f 100644 --- a/src/mcedit2/dialogs/error_dialog.py +++ b/src/mcedit2/dialogs/error_dialog.py @@ -7,26 +7,31 @@ import traceback import sys import platform -from PySide import QtGui +from PySide import QtGui, QtCore from mcedit2.util import qglcontext from mcedit2.util.load_ui import load_ui +from mcedit2.util.screen import centerWidgetInScreen log = logging.getLogger(__name__) + def showErrorDialog(text, tb, fatal): dialog = ErrorDialog(text, tb, fatal) dialog.exec_() + class ErrorDialog(QtGui.QDialog): """ 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 errors in MCEdit itself during signal or event handlers. + Used to report compile and run errors for plugin modules and classes, and + to report errors in MCEdit itself during signal or event handlers. """ def __init__(self, text, exc_info, fatal): super(ErrorDialog, self).__init__() + self.setModal(True) + load_ui("error_dialog.ui", baseinstance=self) exc_type, exc_value, exc_tb = exc_info @@ -49,7 +54,52 @@ class ErrorDialog(QtGui.QDialog): "%s" % (__version__, sys.version, sys.platform, platform.platform(), platform.processor(), contextInfo, text, tbText) + self.errorText = tbText + self.tracebackView.setText(tbText) 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!")) diff --git a/src/mcedit2/ui/error_dialog.ui b/src/mcedit2/ui/error_dialog.ui index a251a50..ac84efb 100644 --- a/src/mcedit2/ui/error_dialog.ui +++ b/src/mcedit2/ui/error_dialog.ui @@ -72,12 +72,19 @@ - + Clicking "Copy to PasteBin" will copy a Pastebin URL to your clipboard. + + + + true + + + @@ -100,6 +107,13 @@ + + + + Restart MCEdit + + +