mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
snapshot of work on new show answer button
This commit is contained in:
parent
0965c3a888
commit
c2176edd07
5 changed files with 84 additions and 53 deletions
|
@ -1445,9 +1445,7 @@ class BrowserToolbar(Toolbar):
|
||||||
right += borderImg("mark", "star16", mark)
|
right += borderImg("mark", "star16", mark)
|
||||||
right += borderImg("pause", "pause16", pause)
|
right += borderImg("pause", "pause16", pause)
|
||||||
self.web.stdHtml(self._body % (
|
self.web.stdHtml(self._body % (
|
||||||
" "+
|
"<span style='display:inline-block; width: 100px;'></span>",
|
||||||
"<span style='font-weight:normal;'>%s</span>"%_("On Selected:"),
|
|
||||||
#' '*20, #<a class="hitem" href="anki">Browser ▾</a>',
|
|
||||||
self._centerLinks(),
|
self._centerLinks(),
|
||||||
right), self._css, focus=False)
|
right), self._css, focus=False)
|
||||||
|
|
||||||
|
|
|
@ -43,15 +43,12 @@ class DeckBrowser(object):
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
_css = """
|
_css = """
|
||||||
.sub { color: #555; }
|
|
||||||
a.deck { color: #000; text-decoration: none; font-size: 12px; }
|
a.deck { color: #000; text-decoration: none; font-size: 12px; }
|
||||||
.num { text-align: right; padding: 0 5 0 5; }
|
a.deck:hover { text-decoration: underline; }
|
||||||
td.opts { white-space: nowrap; }
|
td.opts { white-space: nowrap; }
|
||||||
td.deck { width: 90% }
|
td.deck { width: 90% }
|
||||||
a { font-size: 80%; }
|
|
||||||
.extra { font-size: 90%; }
|
.extra { font-size: 90%; }
|
||||||
.due { vertical-align: text-bottom; }
|
body { margin: 1em; -webkit-user-select: none; }
|
||||||
body { margin: 1em; }
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_body = """
|
_body = """
|
||||||
|
|
|
@ -291,7 +291,6 @@ body {
|
||||||
background: #f3f3f3;
|
background: #f3f3f3;
|
||||||
margin: 2em;
|
margin: 2em;
|
||||||
}
|
}
|
||||||
a:hover { background-color: #aaa; }
|
|
||||||
h1 { margin-bottom: 0.2em; }
|
h1 { margin-bottom: 0.2em; }
|
||||||
hr { margin:5 0 5 0; border:0; height:1px; background-color:#ccc; }
|
hr { margin:5 0 5 0; border:0; height:1px; background-color:#ccc; }
|
||||||
"""
|
"""
|
||||||
|
|
120
aqt/reviewer.py
120
aqt/reviewer.py
|
@ -2,7 +2,7 @@
|
||||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import time, os, stat, shutil, difflib, simplejson
|
import time, os, stat, shutil, difflib, simplejson, re
|
||||||
import unicodedata as ucd
|
import unicodedata as ucd
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from anki.utils import fmtTimeSpan, stripHTML
|
from anki.utils import fmtTimeSpan, stripHTML
|
||||||
|
@ -33,6 +33,8 @@ class Reviewer(object):
|
||||||
else:
|
else:
|
||||||
self.nextCard()
|
self.nextCard()
|
||||||
self.keep = False
|
self.keep = False
|
||||||
|
self.bottom.web.setFixedHeight(60)
|
||||||
|
self.bottom.web.setLinkHandler(self._linkHandler)
|
||||||
|
|
||||||
def lastCard(self):
|
def lastCard(self):
|
||||||
if self._answeredIds:
|
if self._answeredIds:
|
||||||
|
@ -55,7 +57,6 @@ class Reviewer(object):
|
||||||
clearAudioQueue()
|
clearAudioQueue()
|
||||||
if c:
|
if c:
|
||||||
#self.updateMarkAction()
|
#self.updateMarkAction()
|
||||||
self.state = "question"
|
|
||||||
self._initWeb()
|
self._initWeb()
|
||||||
else:
|
else:
|
||||||
self.mw.moveToState("overview")
|
self.mw.moveToState("overview")
|
||||||
|
@ -82,19 +83,11 @@ var hideq;
|
||||||
var ans;
|
var ans;
|
||||||
var typeans;
|
var typeans;
|
||||||
function _updateQA (q) {
|
function _updateQA (q) {
|
||||||
location.hash = "";
|
$("#qa").html(q);
|
||||||
$("#qa").html(q[0]);
|
|
||||||
$("#qa:first").css("height", "100%%");
|
|
||||||
//$("#easebuts").html(q[1]).addClass("inv");
|
|
||||||
//$("#ansbut").show();
|
|
||||||
typeans = document.getElementById("typeans");
|
typeans = document.getElementById("typeans");
|
||||||
if (typeans) {
|
if (typeans) {
|
||||||
typeans.focus();
|
typeans.focus();
|
||||||
}
|
}
|
||||||
// user hook
|
|
||||||
if (typeof(onQuestion) === "function") {
|
|
||||||
onQuestion();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
function _showans (a) {
|
function _showans (a) {
|
||||||
$("#qa").html(a);
|
$("#qa").html(a);
|
||||||
|
@ -110,10 +103,6 @@ function _showans (a) {
|
||||||
}
|
}
|
||||||
//$("#ansbut").hide();
|
//$("#ansbut").hide();
|
||||||
$("#defease").focus();
|
$("#defease").focus();
|
||||||
// user hook
|
|
||||||
if (typeof(onAnswer) === "function") {
|
|
||||||
onAnswer();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
function _processTyped (res) {
|
function _processTyped (res) {
|
||||||
$("#typeans").replaceWith(res);
|
$("#typeans").replaceWith(res);
|
||||||
|
@ -135,32 +124,31 @@ $(".ansbut").focus();
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _initWeb(self):
|
def _initWeb(self):
|
||||||
self.web.stdHtml(self._revHtml % dict(
|
self.web.stdHtml(self._revHtml, self._styles(),
|
||||||
showans=_("Show Answer")), self._styles(),
|
bodyID="card", loadCB=lambda x: self._showQuestion())
|
||||||
bodyID="card",
|
|
||||||
loadCB=lambda x: self._showQuestion())
|
|
||||||
|
|
||||||
# Showing the question (and preparing answer)
|
# Showing the question
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
def _mungeQA(self, buf):
|
||||||
|
return self.mw.col.media.escapeImages(
|
||||||
|
self.prepareTypeAns(mungeQA(buf)))
|
||||||
|
|
||||||
def _showQuestion(self):
|
def _showQuestion(self):
|
||||||
# fixme: timeboxing
|
|
||||||
# fixme: timer
|
|
||||||
self.state = "question"
|
self.state = "question"
|
||||||
c = self.card
|
c = self.card
|
||||||
# mod the card so it shows up in the recently modified list
|
# mod the card so it shows up in the recently modified list
|
||||||
self.card.flush()
|
c.flush()
|
||||||
|
# grab the question and play audio
|
||||||
q = c.q()
|
q = c.q()
|
||||||
a = c.a()
|
|
||||||
if self.mw.pm.profile['autoplay']:
|
if self.mw.pm.profile['autoplay']:
|
||||||
playFromText(q)
|
playFromText(q)
|
||||||
# render
|
# render
|
||||||
esc = self.mw.col.media.escapeImages
|
q = self._mungeQA(q)
|
||||||
q=esc(mungeQA(q)) + self.typeAnsInput()
|
self.web.eval("_updateQA(%s);" % simplejson.dumps(q))
|
||||||
a=esc(mungeQA(a))
|
|
||||||
self.web.eval("_updateQA(%s);" % simplejson.dumps(
|
|
||||||
(q, self._answerButtons())))
|
|
||||||
runHook('showQuestion')
|
runHook('showQuestion')
|
||||||
|
# and refresh bottom bar
|
||||||
|
self._showAnswerButton()
|
||||||
|
|
||||||
# Showing the answer
|
# Showing the answer
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -254,6 +242,7 @@ $(".ansbut").focus();
|
||||||
|
|
||||||
def _linkHandler(self, url):
|
def _linkHandler(self, url):
|
||||||
if url == "ans":
|
if url == "ans":
|
||||||
|
print "show ans"
|
||||||
self._showAnswer()
|
self._showAnswer()
|
||||||
elif url.startswith("ease"):
|
elif url.startswith("ease"):
|
||||||
self._answerCard(int(url[4:]))
|
self._answerCard(int(url[4:]))
|
||||||
|
@ -350,22 +339,28 @@ div#filler {
|
||||||
failedCharColour = "#FF0000"
|
failedCharColour = "#FF0000"
|
||||||
passedCharColour = "#00FF00"
|
passedCharColour = "#00FF00"
|
||||||
|
|
||||||
def typeAns(self):
|
def prepareTypeAns(self, buf):
|
||||||
"None if answer typing disabled."
|
self.typeField = None
|
||||||
print "typeAns()"
|
pat = "\[\[type:(.+?)\]\]"
|
||||||
return False
|
m = re.search(pat, buf)
|
||||||
self.card.template()['typeAns']
|
if not m:
|
||||||
|
return buf
|
||||||
def typeAnsInput(self):
|
fld = m.group(1)
|
||||||
if not self.typeAns():
|
print "got", fld
|
||||||
return ""
|
fobj = None
|
||||||
return """
|
for f in self.card.model()['flds']:
|
||||||
|
if f['name'] == fld:
|
||||||
|
fobj = f
|
||||||
|
break
|
||||||
|
if not fobj:
|
||||||
|
return re.sub(pat, _("Type answer: unknown field %s") % fld, buf)
|
||||||
|
self.typeField = fobj
|
||||||
|
return re.sub(pat, """
|
||||||
<center>
|
<center>
|
||||||
<input type=text id=typeans onkeypress="_typeAnsPress();"
|
<input type=text id=typeans onkeypress="_typeAnsPress();"
|
||||||
style="font-family: '%s'; font-size: %s;">
|
style="font-family: '%s'; font-size: %s;">
|
||||||
</center>
|
</center>
|
||||||
""" % (
|
""" % (fobj['font'], fobj['size']), buf)
|
||||||
self.getFont())
|
|
||||||
|
|
||||||
def processTypedAns(self, given):
|
def processTypedAns(self, given):
|
||||||
ord = self.typeAns()
|
ord = self.typeAns()
|
||||||
|
@ -440,6 +435,49 @@ div#filler {
|
||||||
lastEqual = ""
|
lastEqual = ""
|
||||||
return ret + self.ok(lastEqual)
|
return ret + self.ok(lastEqual)
|
||||||
|
|
||||||
|
# Bottom bar
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
_bottomCSS = """
|
||||||
|
body {
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom,
|
||||||
|
from(#fff), to(#ddd));
|
||||||
|
border-bottom: 0;
|
||||||
|
border-top: 1px solid #aaa;
|
||||||
|
margin: 0;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
td { font-weight: bold; font-size: 12px; }
|
||||||
|
.hitem { padding: 0; }
|
||||||
|
"""
|
||||||
|
_bottomQuestion = """
|
||||||
|
<table width=100%% cellspacing=0 cellpadding=0>
|
||||||
|
<tr>
|
||||||
|
<td width=100>0 + 0 + 0</td>
|
||||||
|
<td align=center>
|
||||||
|
<button onclick='py.link(\"ans\");'>%s</button>
|
||||||
|
</td>
|
||||||
|
<td width=100 align=right>0:00</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<center>
|
||||||
|
<table width=100%% cellspacing=0 cellpadding=0>
|
||||||
|
<tr>
|
||||||
|
<td align=left>
|
||||||
|
<a class=hitem href="foo">Actions ▾</a>
|
||||||
|
</td>
|
||||||
|
<td align=right>
|
||||||
|
<a class=hitem><img src="qrc:/icons/star16.png"></a>
|
||||||
|
<a class=hitem><img src="qrc:/icons/star16.png"></a>
|
||||||
|
</td>
|
||||||
|
</tr></table>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _showAnswerButton(self):
|
||||||
|
self.bottom.web.stdHtml(
|
||||||
|
self._bottomQuestion % _("Show Answer"),
|
||||||
|
self.bottom._css + self._bottomCSS)
|
||||||
|
|
||||||
# Status bar
|
# Status bar
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -91,13 +91,12 @@ margin:0;
|
||||||
background: -webkit-gradient(linear, left top, left bottom,
|
background: -webkit-gradient(linear, left top, left bottom,
|
||||||
from(#ddd), to(#fff));
|
from(#ddd), to(#fff));
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: 1px;
|
|
||||||
border-bottom: 1px solid #aaa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0; padding: 0;
|
margin: 0; padding: 0;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
|
border-bottom: 1px solid #aaa;
|
||||||
}
|
}
|
||||||
|
|
||||||
* { -webkit-user-drag: none; }
|
* { -webkit-user-drag: none; }
|
||||||
|
@ -119,9 +118,9 @@ background: -webkit-gradient(linear, left top, left bottom,
|
||||||
from(#fff), to(#ddd));
|
from(#fff), to(#ddd));
|
||||||
border-bottom: 0;
|
border-bottom: 0;
|
||||||
border-top: 1px solid #aaa;
|
border-top: 1px solid #aaa;
|
||||||
font-weight: normal;
|
|
||||||
margin-bottom: 6px;
|
margin-bottom: 6px;
|
||||||
}
|
}
|
||||||
|
td { font-size: 12px; }
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_centerBody = """
|
_centerBody = """
|
||||||
|
|
Loading…
Reference in a new issue