1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-11-18 13:09:02 +00:00
dupeguru/qt/error_report_dialog.py

97 lines
3.8 KiB
Python
Raw Normal View History

2019-09-10 00:54:28 +00:00
# Created By: Virgil Dupras
# Created On: 2009-05-23
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
#
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
2019-09-10 00:54:28 +00:00
# http://www.gnu.org/licenses/gpl-3.0.html
import traceback
import sys
import os
import platform
2019-09-10 00:54:28 +00:00
from PyQt5.QtCore import Qt, QCoreApplication, QSize
from PyQt5.QtWidgets import (
QDialog,
QVBoxLayout,
QHBoxLayout,
QLabel,
QPlainTextEdit,
QPushButton,
)
2019-09-10 00:54:28 +00:00
from hscommon.trans import trget
from hscommon.desktop import open_url
2022-05-09 00:22:08 +00:00
from qt.util import horizontal_spacer
2019-09-10 00:54:28 +00:00
2022-05-09 00:40:37 +00:00
tr = trget("ui")
2019-09-10 00:54:28 +00:00
class ErrorReportDialog(QDialog):
def __init__(self, parent, github_url, error, **kwargs):
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
super().__init__(parent, flags, **kwargs)
self._setupUi()
name = QCoreApplication.applicationName()
version = QCoreApplication.applicationVersion()
error_text = "Application Name: {}\nVersion: {}\nPython: {}\nOperating System: {}\n\n{}".format(
name, version, platform.python_version(), platform.platform(), error
)
2019-09-10 00:54:28 +00:00
# Under windows, we end up with an error report without linesep if we don't mangle it
2021-08-24 05:12:23 +00:00
error_text = error_text.replace("\n", os.linesep)
self.errorTextEdit.setPlainText(error_text)
2019-09-10 00:54:28 +00:00
self.github_url = github_url
2019-09-10 00:54:28 +00:00
self.sendButton.clicked.connect(self.goToGithub)
self.dontSendButton.clicked.connect(self.reject)
2019-09-10 00:54:28 +00:00
def _setupUi(self):
self.setWindowTitle(tr("Error Report"))
self.resize(553, 349)
self.verticalLayout = QVBoxLayout(self)
self.label = QLabel(self)
self.label.setText(tr("Something went wrong. How about reporting the error?"))
self.label.setWordWrap(True)
self.verticalLayout.addWidget(self.label)
self.errorTextEdit = QPlainTextEdit(self)
self.errorTextEdit.setReadOnly(True)
self.verticalLayout.addWidget(self.errorTextEdit)
msg = tr(
"Error reports should be reported as Github issues. You can copy the error traceback "
"above and paste it in a new issue.\n\nPlease make sure to run a search for any already "
"existing issues beforehand. Also make sure to test the very latest version available from the repository, "
"since the bug you are experiencing might have already been patched.\n\n"
"What usually really helps is if you add a description of how you got the error. Thanks!"
2019-09-10 00:54:28 +00:00
"\n\n"
"Although the application should continue to run after this error, it may be in an "
"unstable state, so it is recommended that you restart the application."
)
self.label2 = QLabel(msg)
self.label2.setWordWrap(True)
self.verticalLayout.addWidget(self.label2)
self.horizontalLayout = QHBoxLayout()
2021-08-24 05:12:23 +00:00
self.horizontalLayout.addItem(horizontal_spacer())
2019-09-10 00:54:28 +00:00
self.dontSendButton = QPushButton(self)
self.dontSendButton.setText(tr("Close"))
self.dontSendButton.setMinimumSize(QSize(110, 0))
self.horizontalLayout.addWidget(self.dontSendButton)
self.sendButton = QPushButton(self)
self.sendButton.setText(tr("Go to Github"))
self.sendButton.setMinimumSize(QSize(110, 0))
self.sendButton.setDefault(True)
self.horizontalLayout.addWidget(self.sendButton)
self.verticalLayout.addLayout(self.horizontalLayout)
2019-09-10 00:54:28 +00:00
def goToGithub(self):
open_url(self.github_url)
2019-09-10 00:54:28 +00:00
def install_excepthook(github_url):
def my_excepthook(exctype, value, tb):
s = "".join(traceback.format_exception(exctype, value, tb))
2019-09-10 00:54:28 +00:00
dialog = ErrorReportDialog(None, github_url, s)
dialog.exec_()
2019-09-10 00:54:28 +00:00
sys.excepthook = my_excepthook