mirror of
https://github.com/ankitects/anki.git
synced 2025-11-10 22:57:11 -05:00
congrats screen; add temporary hack for space bar and pass links through bridge
This commit is contained in:
parent
b5f393c7fe
commit
b699226cfd
2 changed files with 30 additions and 14 deletions
|
|
@ -244,8 +244,8 @@ $(".ansbut").focus();
|
|||
self._answerCard(key)
|
||||
return True
|
||||
|
||||
|
||||
def _linkHandler(self, url):
|
||||
print url
|
||||
if url == "ans":
|
||||
self._showAnswer()
|
||||
elif url.startswith("ease"):
|
||||
|
|
@ -254,6 +254,8 @@ $(".ansbut").focus();
|
|||
self.mw.onAddCard()
|
||||
elif url == "dlist":
|
||||
self.mw.close()
|
||||
elif url == "ov":
|
||||
self.mw.moveToState("overview")
|
||||
|
||||
# CSS
|
||||
##########################################################################
|
||||
|
|
@ -439,22 +441,22 @@ div#filler {
|
|||
def _showCongrats(self):
|
||||
self.state = "congrats"
|
||||
self.card = None
|
||||
self.deck.db.flush()
|
||||
self.hideButtons()
|
||||
self.disableCardMenuItems()
|
||||
self.switchToCongratsScreen()
|
||||
self.form.learnMoreButton.setEnabled(
|
||||
not not self.deck.newAvail)
|
||||
self.startRefreshTimer()
|
||||
self.bodyView.setState(state)
|
||||
# focus finish button
|
||||
self.form.finishButton.setFocus()
|
||||
self.mw.deck.save()
|
||||
buf = """
|
||||
<center>
|
||||
%s
|
||||
<p>
|
||||
<a class=but id=ov href=ov>%s</a>
|
||||
<a class=but href=dlist>%s</a>
|
||||
<script>$("#ov").focus();</script>
|
||||
</center>""" % (self.mw.deck.sched.finishedMsg(),
|
||||
_("Overview"),
|
||||
_("Deck List"))
|
||||
self.web.stdHtml(buf, css=self.mw.sharedCSS)
|
||||
runHook('deckFinished')
|
||||
|
||||
def drawDeckFinishedMessage(self):
|
||||
"Tell the user the deck is finished."
|
||||
self.main.mainWin.congratsLabel.setText(
|
||||
self.main.deck.deckFinishedMsg())
|
||||
|
||||
# Deck empty case
|
||||
##########################################################################
|
||||
|
|
|
|||
|
|
@ -16,8 +16,14 @@ class Bridge(QObject):
|
|||
@pyqtSlot(str, result=str)
|
||||
def run(self, str):
|
||||
return unicode(self._bridge(unicode(str)))
|
||||
@pyqtSlot(str)
|
||||
def link(self, str):
|
||||
print "link", str
|
||||
self._linkHandler(unicode(str))
|
||||
def setBridge(self, func):
|
||||
self._bridge = func
|
||||
def setLinkHandler(self, func):
|
||||
self._linkHandler = func
|
||||
|
||||
# Page for debug messages
|
||||
##########################################################################
|
||||
|
|
@ -42,7 +48,6 @@ class AnkiWebView(QWebView):
|
|||
self._loadFinishedCB = None
|
||||
self.setPage(self._page)
|
||||
self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
||||
self.page().mainFrame().addToJavaScriptWindowObject("py", self._bridge)
|
||||
self.setLinkHandler()
|
||||
self.setKeyHandler()
|
||||
self.connect(self, SIGNAL("linkClicked(QUrl)"), self._linkHandler)
|
||||
|
|
@ -65,6 +70,7 @@ class AnkiWebView(QWebView):
|
|||
self.linkHandler = handler
|
||||
else:
|
||||
self.linkHandler = self._openLinksExternally
|
||||
self._bridge.setLinkHandler(self.linkHandler)
|
||||
def setKeyHandler(self, handler=None):
|
||||
# handler should return true if event should be swallowed
|
||||
self._keyHandler = handler
|
||||
|
|
@ -72,11 +78,19 @@ class AnkiWebView(QWebView):
|
|||
if loadCB:
|
||||
self._loadFinishedCB = loadCB
|
||||
QWebView.setHtml(self, html)
|
||||
self.page().mainFrame().addToJavaScriptWindowObject("py", self._bridge)
|
||||
def stdHtml(self, body, css="", bodyClass="", loadCB=None):
|
||||
self.setHtml("""
|
||||
<html><head><style>%s</style>
|
||||
<script src="qrc:/jquery.min.js"></script>
|
||||
<script src="qrc:/jquery.flot.min.js"></script>
|
||||
<script>
|
||||
$(document).keydown(function(e) {
|
||||
if(e.which==32 && document.activeElement.nodeName == "A") {
|
||||
py.link(document.activeElement.href);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body class="%s">%s</body></html>""" % (css, bodyClass, body), loadCB)
|
||||
# ensure we're focused
|
||||
|
|
|
|||
Loading…
Reference in a new issue