CrashHandler.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import sys
  2. import platform
  3. import traceback
  4. import webbrowser
  5. from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
  6. from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit
  7. def show():
  8. dialog = QDialog()
  9. dialog.setWindowTitle("Oops!")
  10. layout = QVBoxLayout(dialog)
  11. label = QLabel(dialog)
  12. layout.addWidget(label)
  13. 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>")
  14. textarea = QTextEdit(dialog)
  15. layout.addWidget(textarea)
  16. try:
  17. from UM.Application import Application
  18. version = Application.getInstance().getVersion()
  19. except:
  20. version = "Unknown"
  21. trace = "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
  22. crash_info = "Version: {0}\nPlatform: {1}\nQt: {2}\nPyQt: {3}\n\nException:\n{4}"
  23. crash_info = crash_info.format(version, platform.platform(), QT_VERSION_STR, PYQT_VERSION_STR, trace)
  24. textarea.setText(crash_info)
  25. buttons = QDialogButtonBox(QDialogButtonBox.Close, dialog)
  26. layout.addWidget(buttons)
  27. buttons.addButton("Open Web Page", QDialogButtonBox.HelpRole)
  28. buttons.rejected.connect(lambda: dialog.close())
  29. buttons.helpRequested.connect(lambda: webbrowser.open("http://github.com/Ultimaker/Cura/issues"))
  30. dialog.exec_()