Merge pull request #282 from glutanimate/error-dialog-tweaks

Error dialog tweaks
This commit is contained in:
Damien Elmes 2019-02-18 12:39:18 +10:00 committed by GitHub
commit da64f2d7c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions

View file

@ -3,10 +3,12 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import sys, traceback
import html
import re
from anki.lang import _
from aqt.qt import *
from aqt.utils import showText, showWarning
from aqt import mw
if not os.environ.get("DEBUG"):
def excepthook(etype,val,tb):
@ -124,13 +126,26 @@ add-ons section</a> of our support site.
""")
if self.mw.addonManager.dirty:
txt = pluginText
error = self._supportText() + self._addonText(error) + "\n" + error
else:
txt = stdText
# show dialog
error = self._supportText() + "\n" + error
# show dialog
txt = txt + "<div style='white-space: pre-wrap'>" + error + "</div>"
showText(txt, type="html")
showText(txt, type="html", copyBtn=True)
def _addonText(self, error):
matches = re.findall(r"addons21/(.*?)/", error)
if not matches:
return ""
# reverse to list most likely suspect first, dict to deduplicate:
addons = [mw.addonManager.addonName(i) for i in
dict.fromkeys(reversed(matches))]
txt = _("""Potentially affected add-ons: {}\n""")
# highlight importance of first add-on:
addons[0] = "<b>{}</b>".format(addons[0])
return txt.format(", ".join(addons))
def _supportText(self):
import platform

View file

@ -50,7 +50,7 @@ def showInfo(text, parent=False, help="", type="info", title="Anki"):
return mb.exec_()
def showText(txt, parent=None, type="text", run=True, geomKey=None, \
minWidth=500, minHeight=400, title="Anki"):
minWidth=500, minHeight=400, title="Anki", copyBtn=False):
if not parent:
parent = aqt.mw.app.activeWindow() or aqt.mw
diag = QDialog(parent)
@ -66,6 +66,12 @@ def showText(txt, parent=None, type="text", run=True, geomKey=None, \
layout.addWidget(text)
box = QDialogButtonBox(QDialogButtonBox.Close)
layout.addWidget(box)
if copyBtn:
def onCopy():
QApplication.clipboard().setText(text.toPlainText())
btn = QPushButton(_("Copy to Clipboard"))
btn.clicked.connect(onCopy)
box.addButton(btn, QDialogButtonBox.ActionRole)
def onReject():
if geomKey:
saveGeom(diag, geomKey)