hook up context menu and remaining count

This commit is contained in:
Damien Elmes 2011-12-01 17:05:04 +09:00
parent 5dd5ab710a
commit 9c5eb98114
4 changed files with 53 additions and 42 deletions

View file

@ -529,7 +529,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
self.reviewer.card.note().hasTag("marked"))
self.form.actionMarkCard.blockSignals(False)
def onMark(self, toggled):
def onMark(self):
f = self.reviewer.card.note()
if f.hasTag("marked"):
f.delTag("marked")
@ -539,12 +539,13 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
def onSuspend(self):
self.checkpoint(_("Suspend"))
self.col.sched.suspendCards([self.reviewer.card.id])
self.col.sched.suspendCards(
[c.id for c in self.reviewer.card.note().cards()])
self.reviewer.nextCard()
def onDelete(self):
self.checkpoint(_("Delete"))
self.col.remCards([self.reviewer.card.id])
self.col.remNotes([self.reviewer.card.note().id])
self.reviewer.nextCard()
def onBuryNote(self):
@ -771,12 +772,6 @@ Please choose a new deck name:"""))
_(" Please ensure it is set correctly and then restart Anki.")
)
# Sounds
##########################################################################
def onRepeatAudio(self):
self.reviewer.replayAudio()
# Schema modifications
##########################################################################

View file

@ -66,11 +66,6 @@ class Overview(object):
shareLink = '<a class=smallLink href="review">Reviews and Updates</a>'
else:
shareLink = ""
print self._body % dict(
deck=deck['name'],
shareLink=shareLink,
desc=self._desc(deck),
table=self._table())
self.web.stdHtml(self._body % dict(
deck=deck['name'],
shareLink=shareLink,
@ -110,7 +105,7 @@ class Overview(object):
</td><td>%s</td></tr></table>''' % (_("New"), counts[0],
_("In Learning"), counts[1],
_("To Review"), counts[2],
but("study", _("Study")))
but("study", _("Study"), id="study"))
_body = """
<center>
@ -120,6 +115,7 @@ class Overview(object):
<p>
%(table)s
</center>
<script>$(function () { $("#study").focus(); });</script>
"""
_css = """

View file

@ -8,7 +8,7 @@ from aqt.qt import *
from anki.utils import fmtTimeSpan, stripHTML
from anki.hooks import addHook, runHook, runFilter
from anki.sound import playFromText, clearAudioQueue, hasSound
from aqt.utils import mungeQA, getBase
from aqt.utils import mungeQA, getBase, shortcut
import aqt
class Reviewer(object):
@ -68,9 +68,9 @@ class Reviewer(object):
def replayAudio(self):
clearAudioQueue()
c = self.card
if not c.template()['hideQ'] or self.state == "question":
if self.state == "question":
playFromText(c.q())
if self.state == "answer":
elif self.state == "answer":
playFromText(c.a())
# Initializing the webview
@ -186,6 +186,7 @@ function _typeAnsPress() {
############################################################
def _keyHandler(self, evt):
print "rev event", evt.key()
if self.state == "question":
show = False
if evt.key() == Qt.Key_Space and self.typeAns() is None:
@ -363,7 +364,7 @@ button { font-weight: normal; }
return """
<table width=100%% cellspacing=0 cellpadding=0>
<tr>
<td align=left width=50 valign=top class=stat><span class=stattxt>1 + 7 + 3</span><br>
<td align=left width=50 valign=top class=stat><span class=stattxt>%(rem)s</span><br>
<button onclick="py.link('edit');">%(edit)s</button></td>
<td align=center valign=top>
%(middle)s
@ -374,7 +375,7 @@ button { font-weight: normal; }
</tr>
</table>
<script>$(function () { $("#ansbut").focus(); });</script>
""" % dict(middle=middle, edit=_("Edit"), more=_("More"))
""" % dict(middle=middle, rem=self._remaining(), edit=_("Edit"), more=_("More"))
def _showAnswerButton(self):
self.bottom.web.setFocus()
@ -393,6 +394,16 @@ button { font-weight: normal; }
self._bottomHTML(self._answerButtons()),
self.bottom._css + self._bottomCSS)
def _remaining(self):
counts = list(self.mw.col.sched.repCounts())
idx = self.mw.col.sched.countIdx(self.card)
counts[idx] = "<u>%s</u>" % (counts[idx]+1)
space = " + "
ctxt = '<font color="#000099">%s</font>' % counts[0]
ctxt += space + '<font color="#990000">%s</font>' % counts[1]
ctxt += space + '<font color="#007700">%s</font>' % counts[2]
return ctxt
def _defaultEase(self):
if self.mw.col.sched.answerButtons(self.card) == 4:
return 3
@ -430,19 +441,6 @@ button { font-weight: normal; }
txt = self.mw.col.sched.nextIvlStr(self.card, i+1, True)
return '<span class=nobold>%s</span><br>' % txt
# Status bar
##########################################################################
def _remaining(self):
counts = list(self.mw.col.sched.repCounts())
idx = self.mw.col.sched.countIdx(self.card)
counts[idx] = "<u>%s</u>" % (counts[idx]+1)
space = "&nbsp;" * 2
ctxt = '<font color="#000099">%s</font>' % counts[0]
ctxt += space + '<font color="#990000">%s</font>' % counts[1]
ctxt += space + '<font color="#007700">%s</font>' % counts[2]
return ctxt
# Leeches
##########################################################################
@ -457,3 +455,21 @@ Card was a <a href="%s">leech</a>.""") % link)
"select 1 from cards where id = :id and type < 0", id=cardId):
txt += _(" It has been suspended.")
self.setNotice(txt)
# Context menu
##########################################################################
def showContextMenu(self):
opts = [
[_("Replay Audio (r)"), self.replayAudio],
[_("Mark Note (m)"), self.mw.onMark],
[_("Bury Note (b)"), self.mw.onBuryNote],
[_("Suspend Note (!)"), self.mw.onSuspend],
[shortcut(_("Delete Note (Ctrl+delete)")), self.mw.onDelete]
]
m = QMenu(self.mw)
for label, func in opts:
a = m.addAction(label)
a.connect(a, SIGNAL("triggered()"), func)
m.exec_(QCursor.pos())

View file

@ -57,9 +57,10 @@ class Toolbar(object):
######################################################################
def _linkHandler(self, l):
if l == "anki":
self.showMenu()
elif l == "decks":
# first set focus back to main window, or we're left with an ugly
# focus ring around the clicked item
self.mw.web.setFocus()
if l == "decks":
self.mw.moveToState("deckBrowser")
elif l == "study":
# if overview already shown, switch to review
@ -92,12 +93,13 @@ class Toolbar(object):
#header {
font-size: 12px;
margin:0;
background: -webkit-gradient(linear, left top, left bottom,
from(#ddd), to(#fff));
margin-top: 4px;
font-weight: bold;
}
body {
background: -webkit-gradient(linear, left top, left bottom,
from(#ddd), to(#fff));
margin: 0; padding: 0;
-webkit-user-select: none;
border-bottom: 1px solid #aaa;
@ -105,12 +107,13 @@ border-bottom: 1px solid #aaa;
* { -webkit-user-drag: none; }
.hitem { display: inline-block; padding: 4px; padding-right: 6px;
text-decoration: none; color: #000;
.hitem {
padding-right: 6px;
text-decoration: none;
color: #000;
}
.hitem:hover {
background: #333;
color: #fff;
text-decoration: underline;
}
"""
@ -123,6 +126,7 @@ from(#fff), to(#ddd));
border-bottom: 0;
border-top: 1px solid #aaa;
margin-bottom: 6px;
margin-top: 0;
}
td { font-size: 12px; }
"""