mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 06:07:11 -05:00
move height resizing to webview; remove onLoaded from toolbar/reviewer
This commit is contained in:
parent
538678a7a9
commit
37d3996be0
3 changed files with 15 additions and 21 deletions
|
|
@ -92,8 +92,7 @@ class Reviewer:
|
||||||
if self._reps is None or self._reps % 100 == 0:
|
if self._reps is None or self._reps % 100 == 0:
|
||||||
# we recycle the webview periodically so webkit can free memory
|
# we recycle the webview periodically so webkit can free memory
|
||||||
self._initWeb()
|
self._initWeb()
|
||||||
else:
|
self._showQuestion()
|
||||||
self._showQuestion()
|
|
||||||
|
|
||||||
# Audio
|
# Audio
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
@ -126,10 +125,8 @@ class Reviewer:
|
||||||
|
|
||||||
def _initWeb(self):
|
def _initWeb(self):
|
||||||
self._reps = 0
|
self._reps = 0
|
||||||
self._bottomReady = False
|
|
||||||
base = self.mw.baseHTML()
|
base = self.mw.baseHTML()
|
||||||
# main window
|
# main window
|
||||||
self.web.onLoadFinished = self._showQuestion
|
|
||||||
self.web.stdHtml(self._revHtml +
|
self.web.stdHtml(self._revHtml +
|
||||||
self.web.bundledCSS("reviewer.css"), head=base,
|
self.web.bundledCSS("reviewer.css"), head=base,
|
||||||
js=["jquery.js",
|
js=["jquery.js",
|
||||||
|
|
@ -139,7 +136,6 @@ class Reviewer:
|
||||||
"reviewer.js"])
|
"reviewer.js"])
|
||||||
# show answer / ease buttons
|
# show answer / ease buttons
|
||||||
self.bottom.web.show()
|
self.bottom.web.show()
|
||||||
self.bottom.web.onLoadFinished = self._onBottomLoadFinished
|
|
||||||
self.bottom.web.stdHtml(
|
self.bottom.web.stdHtml(
|
||||||
self._bottomHTML(),
|
self._bottomHTML(),
|
||||||
self.bottom._css + self._bottomCSS,
|
self.bottom._css + self._bottomCSS,
|
||||||
|
|
@ -175,8 +171,7 @@ The front of this card is empty. Please run Tools>Empty Cards.""")
|
||||||
|
|
||||||
self.web.eval("_showQuestion(%s, %s, '%s');" % (json.dumps(q), json.dumps(a), bodyclass))
|
self.web.eval("_showQuestion(%s, %s, '%s');" % (json.dumps(q), json.dumps(a), bodyclass))
|
||||||
self._toggleStar()
|
self._toggleStar()
|
||||||
if self._bottomReady:
|
self._showAnswerButton()
|
||||||
self._showAnswerButton()
|
|
||||||
# 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()
|
||||||
|
|
@ -495,11 +490,7 @@ time = %(time)d;
|
||||||
downArrow=downArrow(),
|
downArrow=downArrow(),
|
||||||
time=self.card.timeTaken() // 1000)
|
time=self.card.timeTaken() // 1000)
|
||||||
|
|
||||||
def _onBottomLoadFinished(self):
|
|
||||||
self._showAnswerButton()
|
|
||||||
|
|
||||||
def _showAnswerButton(self):
|
def _showAnswerButton(self):
|
||||||
self._bottomReady = True
|
|
||||||
if not self.typeCorrect:
|
if not self.typeCorrect:
|
||||||
self.bottom.web.setFocus()
|
self.bottom.web.setFocus()
|
||||||
middle = '''
|
middle = '''
|
||||||
|
|
@ -514,7 +505,7 @@ time = %(time)d;
|
||||||
maxTime = 0
|
maxTime = 0
|
||||||
self.bottom.web.eval("showQuestion(%s,%d);" % (
|
self.bottom.web.eval("showQuestion(%s,%d);" % (
|
||||||
json.dumps(middle), maxTime))
|
json.dumps(middle), maxTime))
|
||||||
self.bottom.onLoaded()
|
self.bottom.web.adjustHeightToFit()
|
||||||
|
|
||||||
def _showEaseButtons(self):
|
def _showEaseButtons(self):
|
||||||
self.bottom.web.setFocus()
|
self.bottom.web.setFocus()
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,10 @@ class Toolbar:
|
||||||
}
|
}
|
||||||
self.web.setFixedHeight(30)
|
self.web.setFixedHeight(30)
|
||||||
|
|
||||||
def onLoaded(self):
|
|
||||||
self.web.evalWithCallback("$(document.body).height()", self.onHeight)
|
|
||||||
|
|
||||||
def onHeight(self, qvar):
|
|
||||||
height = int(qvar*self.web.zoomFactor())
|
|
||||||
self.web.setFixedHeight(height)
|
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.web.onBridgeCmd = self._linkHandler
|
self.web.onBridgeCmd = self._linkHandler
|
||||||
self.web.onLoadFinished = self.onLoaded
|
|
||||||
self.web.stdHtml(self._body % self._centerLinks(), self._css)
|
self.web.stdHtml(self._body % self._centerLinks(), self._css)
|
||||||
|
self.web.adjustHeightToFit()
|
||||||
|
|
||||||
# Available links
|
# Available links
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
@ -125,6 +118,9 @@ text-decoration: underline;
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Bottom bar
|
||||||
|
######################################################################
|
||||||
|
|
||||||
class BottomBar(Toolbar):
|
class BottomBar(Toolbar):
|
||||||
|
|
||||||
_css = Toolbar._css + """
|
_css = Toolbar._css + """
|
||||||
|
|
@ -143,7 +139,7 @@ margin-top: 0;
|
||||||
|
|
||||||
def draw(self, buf):
|
def draw(self, buf):
|
||||||
self.web.onBridgeCmd = self._linkHandler
|
self.web.onBridgeCmd = self._linkHandler
|
||||||
self.web.onLoadFinished = self.onLoaded
|
|
||||||
self.web.stdHtml(
|
self.web.stdHtml(
|
||||||
self._centerBody % buf,
|
self._centerBody % buf,
|
||||||
self._css)
|
self._css)
|
||||||
|
self.web.adjustHeightToFit()
|
||||||
|
|
|
||||||
|
|
@ -242,3 +242,10 @@ body { zoom: %f; %s }
|
||||||
def resetHandlers(self):
|
def resetHandlers(self):
|
||||||
self.onBridgeCmd = self.defaultOnBridgeCmd
|
self.onBridgeCmd = self.defaultOnBridgeCmd
|
||||||
self.onLoadFinished = self.defaultOnLoadFinished
|
self.onLoadFinished = self.defaultOnLoadFinished
|
||||||
|
|
||||||
|
def adjustHeightToFit(self):
|
||||||
|
self.evalWithCallback("$(document.body).height()", self._onHeight)
|
||||||
|
|
||||||
|
def _onHeight(self, qvar):
|
||||||
|
height = int(qvar*self.zoomFactor())
|
||||||
|
self.setFixedHeight(height)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue