mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
hook up context menu and remaining count
This commit is contained in:
parent
5dd5ab710a
commit
9c5eb98114
4 changed files with 53 additions and 42 deletions
13
aqt/main.py
13
aqt/main.py
|
@ -529,7 +529,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
self.reviewer.card.note().hasTag("marked"))
|
self.reviewer.card.note().hasTag("marked"))
|
||||||
self.form.actionMarkCard.blockSignals(False)
|
self.form.actionMarkCard.blockSignals(False)
|
||||||
|
|
||||||
def onMark(self, toggled):
|
def onMark(self):
|
||||||
f = self.reviewer.card.note()
|
f = self.reviewer.card.note()
|
||||||
if f.hasTag("marked"):
|
if f.hasTag("marked"):
|
||||||
f.delTag("marked")
|
f.delTag("marked")
|
||||||
|
@ -539,12 +539,13 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
|
||||||
|
|
||||||
def onSuspend(self):
|
def onSuspend(self):
|
||||||
self.checkpoint(_("Suspend"))
|
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()
|
self.reviewer.nextCard()
|
||||||
|
|
||||||
def onDelete(self):
|
def onDelete(self):
|
||||||
self.checkpoint(_("Delete"))
|
self.checkpoint(_("Delete"))
|
||||||
self.col.remCards([self.reviewer.card.id])
|
self.col.remNotes([self.reviewer.card.note().id])
|
||||||
self.reviewer.nextCard()
|
self.reviewer.nextCard()
|
||||||
|
|
||||||
def onBuryNote(self):
|
def onBuryNote(self):
|
||||||
|
@ -771,12 +772,6 @@ Please choose a new deck name:"""))
|
||||||
_(" Please ensure it is set correctly and then restart Anki.")
|
_(" Please ensure it is set correctly and then restart Anki.")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Sounds
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
def onRepeatAudio(self):
|
|
||||||
self.reviewer.replayAudio()
|
|
||||||
|
|
||||||
# Schema modifications
|
# Schema modifications
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -66,11 +66,6 @@ class Overview(object):
|
||||||
shareLink = '<a class=smallLink href="review">Reviews and Updates</a>'
|
shareLink = '<a class=smallLink href="review">Reviews and Updates</a>'
|
||||||
else:
|
else:
|
||||||
shareLink = ""
|
shareLink = ""
|
||||||
print self._body % dict(
|
|
||||||
deck=deck['name'],
|
|
||||||
shareLink=shareLink,
|
|
||||||
desc=self._desc(deck),
|
|
||||||
table=self._table())
|
|
||||||
self.web.stdHtml(self._body % dict(
|
self.web.stdHtml(self._body % dict(
|
||||||
deck=deck['name'],
|
deck=deck['name'],
|
||||||
shareLink=shareLink,
|
shareLink=shareLink,
|
||||||
|
@ -110,7 +105,7 @@ class Overview(object):
|
||||||
</td><td>%s</td></tr></table>''' % (_("New"), counts[0],
|
</td><td>%s</td></tr></table>''' % (_("New"), counts[0],
|
||||||
_("In Learning"), counts[1],
|
_("In Learning"), counts[1],
|
||||||
_("To Review"), counts[2],
|
_("To Review"), counts[2],
|
||||||
but("study", _("Study")))
|
but("study", _("Study"), id="study"))
|
||||||
|
|
||||||
_body = """
|
_body = """
|
||||||
<center>
|
<center>
|
||||||
|
@ -120,6 +115,7 @@ class Overview(object):
|
||||||
<p>
|
<p>
|
||||||
%(table)s
|
%(table)s
|
||||||
</center>
|
</center>
|
||||||
|
<script>$(function () { $("#study").focus(); });</script>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_css = """
|
_css = """
|
||||||
|
|
|
@ -8,7 +8,7 @@ from aqt.qt import *
|
||||||
from anki.utils import fmtTimeSpan, stripHTML
|
from anki.utils import fmtTimeSpan, stripHTML
|
||||||
from anki.hooks import addHook, runHook, runFilter
|
from anki.hooks import addHook, runHook, runFilter
|
||||||
from anki.sound import playFromText, clearAudioQueue, hasSound
|
from anki.sound import playFromText, clearAudioQueue, hasSound
|
||||||
from aqt.utils import mungeQA, getBase
|
from aqt.utils import mungeQA, getBase, shortcut
|
||||||
import aqt
|
import aqt
|
||||||
|
|
||||||
class Reviewer(object):
|
class Reviewer(object):
|
||||||
|
@ -68,9 +68,9 @@ class Reviewer(object):
|
||||||
def replayAudio(self):
|
def replayAudio(self):
|
||||||
clearAudioQueue()
|
clearAudioQueue()
|
||||||
c = self.card
|
c = self.card
|
||||||
if not c.template()['hideQ'] or self.state == "question":
|
if self.state == "question":
|
||||||
playFromText(c.q())
|
playFromText(c.q())
|
||||||
if self.state == "answer":
|
elif self.state == "answer":
|
||||||
playFromText(c.a())
|
playFromText(c.a())
|
||||||
|
|
||||||
# Initializing the webview
|
# Initializing the webview
|
||||||
|
@ -186,6 +186,7 @@ function _typeAnsPress() {
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
def _keyHandler(self, evt):
|
def _keyHandler(self, evt):
|
||||||
|
print "rev event", evt.key()
|
||||||
if self.state == "question":
|
if self.state == "question":
|
||||||
show = False
|
show = False
|
||||||
if evt.key() == Qt.Key_Space and self.typeAns() is None:
|
if evt.key() == Qt.Key_Space and self.typeAns() is None:
|
||||||
|
@ -363,7 +364,7 @@ button { font-weight: normal; }
|
||||||
return """
|
return """
|
||||||
<table width=100%% cellspacing=0 cellpadding=0>
|
<table width=100%% cellspacing=0 cellpadding=0>
|
||||||
<tr>
|
<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>
|
<button onclick="py.link('edit');">%(edit)s</button></td>
|
||||||
<td align=center valign=top>
|
<td align=center valign=top>
|
||||||
%(middle)s
|
%(middle)s
|
||||||
|
@ -374,7 +375,7 @@ button { font-weight: normal; }
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<script>$(function () { $("#ansbut").focus(); });</script>
|
<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):
|
def _showAnswerButton(self):
|
||||||
self.bottom.web.setFocus()
|
self.bottom.web.setFocus()
|
||||||
|
@ -393,6 +394,16 @@ button { font-weight: normal; }
|
||||||
self._bottomHTML(self._answerButtons()),
|
self._bottomHTML(self._answerButtons()),
|
||||||
self.bottom._css + self._bottomCSS)
|
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):
|
def _defaultEase(self):
|
||||||
if self.mw.col.sched.answerButtons(self.card) == 4:
|
if self.mw.col.sched.answerButtons(self.card) == 4:
|
||||||
return 3
|
return 3
|
||||||
|
@ -430,19 +441,6 @@ button { font-weight: normal; }
|
||||||
txt = self.mw.col.sched.nextIvlStr(self.card, i+1, True)
|
txt = self.mw.col.sched.nextIvlStr(self.card, i+1, True)
|
||||||
return '<span class=nobold>%s</span><br>' % txt
|
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 = " " * 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
|
# 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):
|
"select 1 from cards where id = :id and type < 0", id=cardId):
|
||||||
txt += _(" It has been suspended.")
|
txt += _(" It has been suspended.")
|
||||||
self.setNotice(txt)
|
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())
|
||||||
|
|
|
@ -57,9 +57,10 @@ class Toolbar(object):
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def _linkHandler(self, l):
|
def _linkHandler(self, l):
|
||||||
if l == "anki":
|
# first set focus back to main window, or we're left with an ugly
|
||||||
self.showMenu()
|
# focus ring around the clicked item
|
||||||
elif l == "decks":
|
self.mw.web.setFocus()
|
||||||
|
if l == "decks":
|
||||||
self.mw.moveToState("deckBrowser")
|
self.mw.moveToState("deckBrowser")
|
||||||
elif l == "study":
|
elif l == "study":
|
||||||
# if overview already shown, switch to review
|
# if overview already shown, switch to review
|
||||||
|
@ -92,12 +93,13 @@ class Toolbar(object):
|
||||||
#header {
|
#header {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
margin:0;
|
margin:0;
|
||||||
background: -webkit-gradient(linear, left top, left bottom,
|
margin-top: 4px;
|
||||||
from(#ddd), to(#fff));
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom,
|
||||||
|
from(#ddd), to(#fff));
|
||||||
margin: 0; padding: 0;
|
margin: 0; padding: 0;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
border-bottom: 1px solid #aaa;
|
border-bottom: 1px solid #aaa;
|
||||||
|
@ -105,12 +107,13 @@ border-bottom: 1px solid #aaa;
|
||||||
|
|
||||||
* { -webkit-user-drag: none; }
|
* { -webkit-user-drag: none; }
|
||||||
|
|
||||||
.hitem { display: inline-block; padding: 4px; padding-right: 6px;
|
.hitem {
|
||||||
text-decoration: none; color: #000;
|
padding-right: 6px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #000;
|
||||||
}
|
}
|
||||||
.hitem:hover {
|
.hitem:hover {
|
||||||
background: #333;
|
text-decoration: underline;
|
||||||
color: #fff;
|
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -123,6 +126,7 @@ from(#fff), to(#ddd));
|
||||||
border-bottom: 0;
|
border-bottom: 0;
|
||||||
border-top: 1px solid #aaa;
|
border-top: 1px solid #aaa;
|
||||||
margin-bottom: 6px;
|
margin-bottom: 6px;
|
||||||
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
td { font-size: 12px; }
|
td { font-size: 12px; }
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue