reuse the main webview during reviews

This commit is contained in:
Damien Elmes 2012-02-24 21:37:23 +09:00
parent b2919f285d
commit ada11b246b

View file

@ -35,6 +35,7 @@ class Reviewer(object):
else: else:
self.bottom.web.setFixedHeight(52) self.bottom.web.setFixedHeight(52)
self.bottom.web.setLinkHandler(self._linkHandler) self.bottom.web.setLinkHandler(self._linkHandler)
self._reps = None
self.nextCard() self.nextCard()
def lastCard(self): def lastCard(self):
@ -63,10 +64,14 @@ class Reviewer(object):
c = self.mw.col.sched.getCard() c = self.mw.col.sched.getCard()
self.card = c self.card = c
clearAudioQueue() clearAudioQueue()
if c: if not c:
self.mw.moveToState("overview")
return
if self._reps is None or self._reps % 100 == 0:
# we recycle the webview periodically so webkit can free memory
self._initWeb() self._initWeb()
else: else:
self.mw.moveToState("overview") self._showQuestion()
# Audio # Audio
########################################################################## ##########################################################################
@ -111,6 +116,7 @@ function _typeAnsPress() {
""" """
def _initWeb(self): def _initWeb(self):
self._reps = 0
base = getBase(self.mw.col) base = getBase(self.mw.col)
self.web.stdHtml(self._revHtml, self._styles(), self.web.stdHtml(self._revHtml, self._styles(),
bodyClass="card", loadCB=lambda x: self._showQuestion(), bodyClass="card", loadCB=lambda x: self._showQuestion(),
@ -124,6 +130,7 @@ function _typeAnsPress() {
self.typeAnsFilter(mungeQA(buf))) self.typeAnsFilter(mungeQA(buf)))
def _showQuestion(self): def _showQuestion(self):
self._reps += 1
self.state = "question" self.state = "question"
c = self.card c = self.card
# grab the question and play audio # grab the question and play audio
@ -133,7 +140,9 @@ function _typeAnsPress() {
# render & update bottom # render & update bottom
q = self._mungeQA(q) q = self._mungeQA(q)
self.web.eval("_updateQA(%s);" % simplejson.dumps(q)) self.web.eval("_updateQA(%s);" % simplejson.dumps(q))
t = time.time()
self._showAnswerButton() self._showAnswerButton()
print (time.time() - t)*1000
# if we have a type answer field, focus main web # if we have a type answer field, focus main web
if self.typeCorrect: if self.typeCorrect:
self.mw.web.setFocus() self.mw.web.setFocus()
@ -438,7 +447,6 @@ var updateTime = function () {
self._remaining(), _("Show Answer")) self._remaining(), _("Show Answer"))
# wrap it in a table so it has the same top margin as the ease buttons # wrap it in a table so it has the same top margin as the ease buttons
middle = "<table cellpadding=0><tr><td class=stat2 align=center>%s</td></tr></table>" % middle middle = "<table cellpadding=0><tr><td class=stat2 align=center>%s</td></tr></table>" % middle
self.bottom.web.stdHtml( self.bottom.web.stdHtml(
self._bottomHTML(middle), self._bottomHTML(middle),
self.bottom._css + self._bottomCSS) self.bottom._css + self._bottomCSS)