From 55b782581d39f3a4b184ff3f24a59d51ad8c9e83 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 10 Aug 2017 21:39:04 +1000 Subject: [PATCH] global reviewer override, fix fading in previewer/clayout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit you can use the debug console to define custom html/css/js to be added to the bottom of the reviewer on all note types, so to increase the fade time on the question you'd use mw.col.conf["reviewExtra"]="" mw.col.setMod() also make sure the fading for question/answer is used correctly in previewer, and use answer fading in clayout to speed it up --- aqt/browser.py | 6 ++++-- aqt/clayout.py | 7 ++++--- aqt/reviewer.py | 7 +++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/aqt/browser.py b/aqt/browser.py index 6fd359b7d..da71887d9 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -1118,7 +1118,7 @@ where id in %s""" % ids2str(sf)) jsinc = ["jquery.js","browsersel.js", "mathjax/conf.js", "mathjax/MathJax.js", "reviewer.js"] - self._previewWeb.stdHtml(self.mw.reviewer._revHtml, + self._previewWeb.stdHtml(self.mw.reviewer.revHtml(), css=["reviewer.css"], head=base, js=jsinc) @@ -1146,6 +1146,7 @@ where id in %s""" % ids2str(sf)) return c = self.card self._updatePreviewButtons() + func = "_showQuestion" if not c or not self.singleCard: txt = _("(please select 1 card)") bodyclass = "" @@ -1155,6 +1156,7 @@ where id in %s""" % ids2str(sf)) # need to force reload even if answer txt = c.q(reload=True) if self._previewState == "answer": + func = "_showAnswer" txt = c.a() txt = re.sub("\[\[type:[^]]+\]\]", "", txt) @@ -1167,7 +1169,7 @@ where id in %s""" % ids2str(sf)) txt = mungeQA(self.col, txt) self._previewWeb.eval( - "_showQuestion(%s,'%s');" % (json.dumps(txt), bodyclass)) + f"{func}({json.dumps(txt)},'{bodyclass}');") # Card deletion ###################################################################### diff --git a/aqt/clayout.py b/aqt/clayout.py index c75bd907b..24a991fed 100644 --- a/aqt/clayout.py +++ b/aqt/clayout.py @@ -174,10 +174,10 @@ class CardLayout(QDialog): jsinc = ["jquery.js","browsersel.js", "mathjax/conf.js", "mathjax/MathJax.js", "reviewer.js"] - pform.frontWeb.stdHtml(self.mw.reviewer._revHtml, + pform.frontWeb.stdHtml(self.mw.reviewer.revHtml(), css=["reviewer.css"], head=base, js=jsinc) - pform.backWeb.stdHtml(self.mw.reviewer._revHtml, + pform.backWeb.stdHtml(self.mw.reviewer.revHtml(), css=["reviewer.css"], head=base, js=jsinc) @@ -290,7 +290,8 @@ Please create a new card type first.""")) q = ti(mungeQA(self.mw.col, c.q(reload=True))) a = ti(mungeQA(self.mw.col, c.a()), type='a') - self.pform.frontWeb.eval("_showQuestion(%s,'%s');" % (json.dumps(q), bodyclass)) + # use _showAnswer to avoid the longer delay + self.pform.frontWeb.eval("_showAnswer(%s,'%s');" % (json.dumps(q), bodyclass)) self.pform.backWeb.eval("_showAnswer(%s, '%s');" % (json.dumps(a), bodyclass)) clearAudioQueue() diff --git a/aqt/reviewer.py b/aqt/reviewer.py index fd7811d19..f341dda1f 100644 --- a/aqt/reviewer.py +++ b/aqt/reviewer.py @@ -117,16 +117,19 @@ class Reviewer: # Initializing the webview ########################################################################## - _revHtml = """ + def revHtml(self): + extra = self.mw.col.conf.get("reviewExtra", "") + return f"""
+{extra} """ def _initWeb(self): self._reps = 0 base = self.mw.baseHTML() # main window - self.web.stdHtml(self._revHtml, + self.web.stdHtml(self.revHtml(), head=base, css=["reviewer.css"], js=["jquery.js",