mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Merge pull request #282 from glutanimate/error-dialog-tweaks
Error dialog tweaks
This commit is contained in:
commit
da64f2d7c8
2 changed files with 26 additions and 5 deletions
|
@ -3,10 +3,12 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import sys, traceback
|
import sys, traceback
|
||||||
import html
|
import html
|
||||||
|
import re
|
||||||
|
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import showText, showWarning
|
from aqt.utils import showText, showWarning
|
||||||
|
from aqt import mw
|
||||||
|
|
||||||
if not os.environ.get("DEBUG"):
|
if not os.environ.get("DEBUG"):
|
||||||
def excepthook(etype,val,tb):
|
def excepthook(etype,val,tb):
|
||||||
|
@ -121,16 +123,29 @@ report the issue on the <a href="https://help.ankiweb.net/discussions/add-ons/">
|
||||||
add-ons section</a> of our support site.
|
add-ons section</a> of our support site.
|
||||||
|
|
||||||
<p>Debug info:</p>
|
<p>Debug info:</p>
|
||||||
""")
|
""")
|
||||||
if self.mw.addonManager.dirty:
|
if self.mw.addonManager.dirty:
|
||||||
txt = pluginText
|
txt = pluginText
|
||||||
|
error = self._supportText() + self._addonText(error) + "\n" + error
|
||||||
else:
|
else:
|
||||||
txt = stdText
|
txt = stdText
|
||||||
|
error = self._supportText() + "\n" + error
|
||||||
|
|
||||||
# show dialog
|
# show dialog
|
||||||
error = self._supportText() + "\n" + error
|
|
||||||
|
|
||||||
txt = txt + "<div style='white-space: pre-wrap'>" + error + "</div>"
|
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):
|
def _supportText(self):
|
||||||
import platform
|
import platform
|
||||||
|
|
|
@ -50,7 +50,7 @@ def showInfo(text, parent=False, help="", type="info", title="Anki"):
|
||||||
return mb.exec_()
|
return mb.exec_()
|
||||||
|
|
||||||
def showText(txt, parent=None, type="text", run=True, geomKey=None, \
|
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:
|
if not parent:
|
||||||
parent = aqt.mw.app.activeWindow() or aqt.mw
|
parent = aqt.mw.app.activeWindow() or aqt.mw
|
||||||
diag = QDialog(parent)
|
diag = QDialog(parent)
|
||||||
|
@ -66,6 +66,12 @@ def showText(txt, parent=None, type="text", run=True, geomKey=None, \
|
||||||
layout.addWidget(text)
|
layout.addWidget(text)
|
||||||
box = QDialogButtonBox(QDialogButtonBox.Close)
|
box = QDialogButtonBox(QDialogButtonBox.Close)
|
||||||
layout.addWidget(box)
|
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():
|
def onReject():
|
||||||
if geomKey:
|
if geomKey:
|
||||||
saveGeom(diag, geomKey)
|
saveGeom(diag, geomKey)
|
||||||
|
|
Loading…
Reference in a new issue