From 569f42c0f5a1b9aba3330807527052c61fe017d7 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sun, 24 Feb 2019 14:50:39 +0100 Subject: [PATCH 1/3] Move supportText() to utils in order to allow use outside of errors --- aqt/errors.py | 30 +++--------------------------- aqt/utils.py | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/aqt/errors.py b/aqt/errors.py index 821be049e..274822050 100644 --- a/aqt/errors.py +++ b/aqt/errors.py @@ -7,7 +7,7 @@ import re from anki.lang import _ from aqt.qt import * -from aqt.utils import showText, showWarning +from aqt.utils import showText, showWarning, supportText from aqt import mw if not os.environ.get("DEBUG"): @@ -126,10 +126,10 @@ add-ons section of our support site. """) if self.mw.addonManager.dirty: txt = pluginText - error = self._supportText() + self._addonText(error) + "\n" + error + error = supportText() + self._addonText(error) + "\n" + error else: txt = stdText - error = self._supportText() + "\n" + error + error = supportText() + "\n" + error # show dialog txt = txt + "
" + error + "
" @@ -146,27 +146,3 @@ add-ons section of our support site. # highlight importance of first add-on: addons[0] = "{}".format(addons[0]) return txt.format(", ".join(addons)) - - def _supportText(self): - import platform - from aqt.utils import versionWithBuild - - if isWin: - platname = "Windows " + platform.win32_ver()[0] - elif isMac: - platname = "Mac " + platform.mac_ver()[0] - else: - platname = "Linux" - - def schedVer(): - try: - return self.mw.col.schedVer() - except: - return "?" - - return """\ -Anki {} Python {} Qt {} PyQt {} -Platform: {} -Flags: frz={} ao={} sv={} -""".format(versionWithBuild(), platform.python_version(), QT_VERSION_STR, PYQT_VERSION_STR, platname, - getattr(sys, "frozen", False), self.mw.addonManager.dirty, schedVer()) diff --git a/aqt/utils.py b/aqt/utils.py index ee74071f7..b8ae7e5f2 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -567,6 +567,33 @@ def versionWithBuild(): build = "dev" return "%s (%s)" % (appVersion, build) +def supportText(): + import platform + from aqt import mw + from aqt.utils import versionWithBuild + + if isWin: + platname = "Windows " + platform.win32_ver()[0] + elif isMac: + platname = "Mac " + platform.mac_ver()[0] + else: + platname = "Linux" + + def schedVer(): + try: + return mw.col.schedVer() + except: + return "?" + + return """\ +Anki {} Python {} Qt {} PyQt {} +Platform: {} +Flags: frz={} ao={} sv={} +""".format(versionWithBuild(), platform.python_version(), + QT_VERSION_STR, PYQT_VERSION_STR, platname, + getattr(sys, "frozen", False), + mw.addonManager.dirty, schedVer()) + ###################################################################### # adapted from version detection in qutebrowser From c45ea26cd65b7910667075bb58b589b5b756257c Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sun, 24 Feb 2019 14:51:19 +0100 Subject: [PATCH 2/3] Move annotatedName to AddonManager to allow outside access --- aqt/addons.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/aqt/addons.py b/aqt/addons.py index 6fd94990b..05b2d769b 100644 --- a/aqt/addons.py +++ b/aqt/addons.py @@ -115,6 +115,12 @@ When loading '%(name)s': def addonName(self, dir): return self.addonMeta(dir).get("name", dir) + def annotatedName(self, dir): + buf = self.addonName(dir) + if not self.isEnabled(dir): + buf += _(" (disabled)") + return buf + # Conflict resolution ###################################################################### @@ -456,7 +462,7 @@ class AddonsDialog(QDialog): addonList = self.form.addonList mgr = self.mgr - self.addons = [(self.annotatedName(d), d) for d in mgr.allAddons()] + self.addons = [(mgr.annotatedName(d), d) for d in mgr.allAddons()] self.addons.sort() selected = set(self.selectedAddons()) @@ -477,12 +483,6 @@ class AddonsDialog(QDialog): addon = '' self.form.viewPage.setEnabled(bool (re.match(r"^\d+$", addon))) - def annotatedName(self, dir): - buf = self.mgr.addonName(dir) - if not self.mgr.isEnabled(dir): - buf += _(" (disabled)") - return buf - def selectedAddons(self): idxs = [x.row() for x in self.form.addonList.selectedIndexes()] return [self.addons[idx][1] for idx in idxs] From 4fd5a9c176f5264ed960f735082e49a55816ef25 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sun, 24 Feb 2019 14:55:55 +0100 Subject: [PATCH 3/3] Add a button to copy debug information to About dialog Supplies information on platform, app, toolkit, and installed add-ons. Should come in useful to troubleshoot issues that do not produce an error message, especially for add-on developers. --- aqt/about.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/aqt/about.py b/aqt/about.py index 0baa2e9f7..a209a45bb 100644 --- a/aqt/about.py +++ b/aqt/about.py @@ -4,7 +4,7 @@ from aqt.qt import * import aqt.forms -from aqt.utils import versionWithBuild +from aqt.utils import versionWithBuild, supportText, tooltip class ClosableQDialog(QDialog): def reject(self): @@ -24,6 +24,23 @@ def show(mw): mw.setupDialogGC(dialog) abt = aqt.forms.about.Ui_About() abt.setupUi(dialog) + + # Copy debug info + ###################################################################### + def onCopy(): + addmgr = mw.addonManager + addons = "\n".join(addmgr.annotatedName(d) for d in addmgr.allAddons()) + info = "\n".join((supportText(), "Add-ons:\n\n{}".format(addons))) + QApplication.clipboard().setText(info) + tooltip(_("Copied to clipboard"), parent=dialog) + + btn = QPushButton(_("Copy Debug Info")) + btn.clicked.connect(onCopy) + abt.buttonBox.addButton(btn, QDialogButtonBox.ActionRole) + abt.buttonBox.button(QDialogButtonBox.Ok).setFocus() + + # WebView contents + ###################################################################### abouttext = "
" abouttext += '

' + _("Anki is a friendly, intelligent spaced learning \ system. It's free and open source.")