2012-12-21 08:51:59 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-02-05 04:59:03 +01:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
2012-12-21 08:51:59 +01:00
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
2020-01-22 01:46:35 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
import aqt
|
2019-03-04 02:58:34 +01:00
|
|
|
from anki.lang import _
|
2020-02-08 06:31:41 +01:00
|
|
|
from aqt import gui_hooks
|
2020-01-20 11:10:38 +01:00
|
|
|
from aqt.sound import av_player
|
2020-01-22 01:46:35 +01:00
|
|
|
from aqt.toolbar import BottomBar
|
2019-12-20 10:19:03 +01:00
|
|
|
from aqt.utils import askUserDialog, openLink, shortcut, tooltip
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-08 23:59:29 +01:00
|
|
|
class OverviewBottomBar:
|
|
|
|
def __init__(self, overview: Overview):
|
|
|
|
self.overview = overview
|
|
|
|
|
|
|
|
|
2017-02-06 23:21:33 +01:00
|
|
|
class Overview:
|
2012-12-21 08:51:59 +01:00
|
|
|
"Deck overview."
|
|
|
|
|
2020-01-22 01:46:35 +01:00
|
|
|
def __init__(self, mw: aqt.AnkiQt) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw = mw
|
|
|
|
self.web = mw.web
|
2020-01-22 01:46:35 +01:00
|
|
|
self.bottom = BottomBar(mw, mw.bottomWeb)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def show(self):
|
2020-01-20 11:10:38 +01:00
|
|
|
av_player.stop_and_clear_queue()
|
2020-02-08 23:59:29 +01:00
|
|
|
self.web.set_bridge_command(self._linkHandler, self)
|
2017-06-22 08:36:54 +02:00
|
|
|
self.mw.setStateShortcuts(self._shortcutKeys())
|
2012-12-21 08:51:59 +01:00
|
|
|
self.refresh()
|
|
|
|
|
|
|
|
def refresh(self):
|
|
|
|
self.mw.col.reset()
|
|
|
|
self._renderPage()
|
|
|
|
self._renderBottom()
|
2016-05-31 10:51:40 +02:00
|
|
|
self.mw.web.setFocus()
|
2020-02-08 06:31:41 +01:00
|
|
|
gui_hooks.overview_did_refresh(self)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Handlers
|
|
|
|
############################################################
|
|
|
|
|
|
|
|
def _linkHandler(self, url):
|
|
|
|
if url == "study":
|
|
|
|
self.mw.col.startTimebox()
|
|
|
|
self.mw.moveToState("review")
|
2013-04-11 07:57:03 +02:00
|
|
|
if self.mw.state == "overview":
|
|
|
|
tooltip(_("No cards are due yet."))
|
2012-12-21 08:51:59 +01:00
|
|
|
elif url == "anki":
|
2016-05-12 06:45:35 +02:00
|
|
|
print("anki menu")
|
2012-12-21 08:51:59 +01:00
|
|
|
elif url == "opts":
|
|
|
|
self.mw.onDeckConf()
|
|
|
|
elif url == "cram":
|
|
|
|
deck = self.mw.col.decks.current()
|
2019-12-23 01:34:10 +01:00
|
|
|
self.mw.onCram("'deck:%s'" % deck["name"])
|
2012-12-21 08:51:59 +01:00
|
|
|
elif url == "refresh":
|
|
|
|
self.mw.col.sched.rebuildDyn()
|
|
|
|
self.mw.reset()
|
|
|
|
elif url == "empty":
|
|
|
|
self.mw.col.sched.emptyDyn(self.mw.col.decks.selected())
|
|
|
|
self.mw.reset()
|
|
|
|
elif url == "decks":
|
|
|
|
self.mw.moveToState("deckBrowser")
|
|
|
|
elif url == "review":
|
2019-12-23 01:34:10 +01:00
|
|
|
openLink(aqt.appShared + "info/%s?v=%s" % (self.sid, self.sidVer))
|
2012-12-21 08:51:59 +01:00
|
|
|
elif url == "studymore":
|
|
|
|
self.onStudyMore()
|
rework sibling handling and change bury semantics
First, burying changes:
- unburying now happens on day rollover, or when manually unburying from
overview screen
- burying is not performed when returning to deck list, or when closing
collection, so burying now must mark cards as modified to ensure sync
consistent
- because they're no longer temporary to a session, make sure we exclude them
in filtered decks in -is:suspended
Sibling spacing changes:
- core behaviour now based on automatically burying related cards when we
answer a card
- applies to reviews, optionally to new cards, and never to cards in the
learning queue (partly because we can't suspend/bury cards in that queue at
the moment)
- this means spacing works consistently in filtered decks now, works on
reviews even when user is late to review, and provides better separation of
new cards
- if burying new cards disabled, we just discard them from the current queue.
an option to set due=ord*space+due would be nicer, but would require
changing a lot of code and is more appropriate for a future major version
change. discarding from queue suffers from the same issue as the new card
cycling in that queue rebuilds may cause cards to be shown close together,
so the default burying behaviour is preferable
- refer to them as 'related cards' rather than 'siblings'
These changes don't require any changes to the database format, so they
should hopefully coexist with older clients without issue.
2013-08-10 08:54:33 +02:00
|
|
|
elif url == "unbury":
|
2017-12-27 06:17:53 +01:00
|
|
|
self.onUnbury()
|
2013-01-14 23:42:38 +01:00
|
|
|
elif url.lower().startswith("http"):
|
2012-12-21 08:51:59 +01:00
|
|
|
openLink(url)
|
2016-05-31 10:51:40 +02:00
|
|
|
return False
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2017-06-22 08:36:54 +02:00
|
|
|
def _shortcutKeys(self):
|
|
|
|
return [
|
|
|
|
("o", self.mw.onDeckConf),
|
|
|
|
("r", self.onRebuildKey),
|
|
|
|
("e", self.onEmptyKey),
|
|
|
|
("c", self.onCustomStudyKey),
|
2019-12-23 01:34:10 +01:00
|
|
|
("u", self.onUnbury),
|
2017-06-22 08:36:54 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def _filteredDeck(self):
|
2019-12-23 01:34:10 +01:00
|
|
|
return self.mw.col.decks.current()["dyn"]
|
2017-06-22 08:36:54 +02:00
|
|
|
|
|
|
|
def onRebuildKey(self):
|
|
|
|
if self._filteredDeck():
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw.col.sched.rebuildDyn()
|
|
|
|
self.mw.reset()
|
2017-06-22 08:36:54 +02:00
|
|
|
|
|
|
|
def onEmptyKey(self):
|
|
|
|
if self._filteredDeck():
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw.col.sched.emptyDyn(self.mw.col.decks.selected())
|
|
|
|
self.mw.reset()
|
2017-06-22 08:36:54 +02:00
|
|
|
|
|
|
|
def onCustomStudyKey(self):
|
|
|
|
if not self._filteredDeck():
|
2012-12-21 08:51:59 +01:00
|
|
|
self.onStudyMore()
|
2017-06-22 08:36:54 +02:00
|
|
|
|
2017-12-27 06:17:53 +01:00
|
|
|
def onUnbury(self):
|
2018-01-26 10:04:02 +01:00
|
|
|
if self.mw.col.schedVer() == 1:
|
|
|
|
self.mw.col.sched.unburyCardsForDeck()
|
|
|
|
self.mw.reset()
|
|
|
|
return
|
|
|
|
|
2017-12-27 06:17:53 +01:00
|
|
|
sibs = self.mw.col.sched.haveBuriedSiblings()
|
|
|
|
man = self.mw.col.sched.haveManuallyBuried()
|
|
|
|
|
|
|
|
if sibs and man:
|
2019-12-23 01:34:10 +01:00
|
|
|
opts = [
|
|
|
|
_("Manually Buried Cards"),
|
|
|
|
_("Buried Siblings"),
|
|
|
|
_("All Buried Cards"),
|
|
|
|
_("Cancel"),
|
|
|
|
]
|
2017-12-27 06:17:53 +01:00
|
|
|
|
|
|
|
diag = askUserDialog(_("What would you like to unbury?"), opts)
|
|
|
|
diag.setDefault(0)
|
|
|
|
ret = diag.run()
|
|
|
|
if ret == opts[0]:
|
|
|
|
self.mw.col.sched.unburyCardsForDeck(type="manual")
|
|
|
|
elif ret == opts[1]:
|
|
|
|
self.mw.col.sched.unburyCardsForDeck(type="siblings")
|
|
|
|
elif ret == opts[2]:
|
|
|
|
self.mw.col.sched.unburyCardsForDeck(type="all")
|
|
|
|
else:
|
|
|
|
self.mw.col.sched.unburyCardsForDeck(type="all")
|
|
|
|
|
2017-06-22 08:36:54 +02:00
|
|
|
self.mw.reset()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# HTML
|
|
|
|
############################################################
|
|
|
|
|
|
|
|
def _renderPage(self):
|
|
|
|
but = self.mw.button
|
|
|
|
deck = self.mw.col.decks.current()
|
|
|
|
self.sid = deck.get("sharedFrom")
|
|
|
|
if self.sid:
|
|
|
|
self.sidVer = deck.get("ver", None)
|
|
|
|
shareLink = '<a class=smallLink href="review">Reviews and Updates</a>'
|
|
|
|
else:
|
|
|
|
shareLink = ""
|
2019-12-23 01:34:10 +01:00
|
|
|
self.web.stdHtml(
|
|
|
|
self._body
|
|
|
|
% dict(
|
|
|
|
deck=deck["name"],
|
2017-08-10 11:02:32 +02:00
|
|
|
shareLink=shareLink,
|
|
|
|
desc=self._desc(deck),
|
2019-12-23 01:34:10 +01:00
|
|
|
table=self._table(),
|
2017-08-10 11:02:32 +02:00
|
|
|
),
|
2020-02-12 22:00:13 +01:00
|
|
|
css=["_anki/overview.css"],
|
|
|
|
js=["_anki/jquery.js", "_anki/overview.js"],
|
|
|
|
context=self,
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def _desc(self, deck):
|
2019-12-23 01:34:10 +01:00
|
|
|
if deck["dyn"]:
|
|
|
|
desc = _(
|
|
|
|
"""\
|
|
|
|
This is a special deck for studying outside of the normal schedule."""
|
|
|
|
)
|
|
|
|
desc += " " + _(
|
|
|
|
"""\
|
2012-12-21 08:51:59 +01:00
|
|
|
Cards will be automatically returned to their original decks after you review \
|
2019-12-23 01:34:10 +01:00
|
|
|
them."""
|
|
|
|
)
|
|
|
|
desc += " " + _(
|
|
|
|
"""\
|
2012-12-21 08:51:59 +01:00
|
|
|
Deleting this deck from the deck list will return all remaining cards \
|
2019-12-23 01:34:10 +01:00
|
|
|
to their original deck."""
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
|
|
|
desc = deck.get("desc", "")
|
|
|
|
if not desc:
|
|
|
|
return "<p>"
|
2019-12-23 01:34:10 +01:00
|
|
|
if deck["dyn"]:
|
2012-12-21 08:51:59 +01:00
|
|
|
dyn = "dyn"
|
|
|
|
else:
|
|
|
|
dyn = ""
|
2019-12-23 01:34:10 +01:00
|
|
|
return '<div class="descfont descmid description %s">%s</div>' % (dyn, desc)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def _table(self):
|
|
|
|
counts = list(self.mw.col.sched.counts())
|
|
|
|
finished = not sum(counts)
|
2018-07-11 12:03:36 +02:00
|
|
|
if self.mw.col.schedVer() == 1:
|
|
|
|
for n in range(len(counts)):
|
|
|
|
if counts[n] >= 1000:
|
|
|
|
counts[n] = "1000+"
|
2012-12-21 08:51:59 +01:00
|
|
|
but = self.mw.button
|
|
|
|
if finished:
|
|
|
|
return '<div style="white-space: pre-wrap;">%s</div>' % (
|
2019-12-23 01:34:10 +01:00
|
|
|
self.mw.col.sched.finishedMsg()
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
2019-12-23 01:34:10 +01:00
|
|
|
return """
|
2018-09-28 09:54:43 +02:00
|
|
|
<table width=400 cellpadding=5>
|
2012-12-21 08:51:59 +01:00
|
|
|
<tr><td align=center valign=top>
|
|
|
|
<table cellspacing=5>
|
2020-01-23 06:08:10 +01:00
|
|
|
<tr><td>%s:</td><td><b><span class=new-count>%s</span></b></td></tr>
|
|
|
|
<tr><td>%s:</td><td><b><font class=learn-count>%s</span></b></td></tr>
|
|
|
|
<tr><td>%s:</td><td><b><span class=review-count>%s</span></b></td></tr>
|
2012-12-21 08:51:59 +01:00
|
|
|
</table>
|
|
|
|
</td><td align=center>
|
2019-12-23 01:34:10 +01:00
|
|
|
%s</td></tr></table>""" % (
|
|
|
|
_("New"),
|
|
|
|
counts[0],
|
|
|
|
_("Learning"),
|
|
|
|
counts[1],
|
|
|
|
_("To Review"),
|
|
|
|
counts[2],
|
|
|
|
but("study", _("Study Now"), id="study", extra=" autofocus"),
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
_body = """
|
|
|
|
<center>
|
|
|
|
<h3>%(deck)s</h3>
|
|
|
|
%(shareLink)s
|
|
|
|
%(desc)s
|
|
|
|
%(table)s
|
|
|
|
</center>
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Bottom area
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def _renderBottom(self):
|
|
|
|
links = [
|
2013-02-20 07:27:42 +01:00
|
|
|
["O", "opts", _("Options")],
|
2012-12-21 08:51:59 +01:00
|
|
|
]
|
2019-12-23 01:34:10 +01:00
|
|
|
if self.mw.col.decks.current()["dyn"]:
|
2012-12-21 08:51:59 +01:00
|
|
|
links.append(["R", "refresh", _("Rebuild")])
|
|
|
|
links.append(["E", "empty", _("Empty")])
|
|
|
|
else:
|
|
|
|
links.append(["C", "studymore", _("Custom Study")])
|
2019-12-23 01:34:10 +01:00
|
|
|
# links.append(["F", "cram", _("Filter/Cram")])
|
rework sibling handling and change bury semantics
First, burying changes:
- unburying now happens on day rollover, or when manually unburying from
overview screen
- burying is not performed when returning to deck list, or when closing
collection, so burying now must mark cards as modified to ensure sync
consistent
- because they're no longer temporary to a session, make sure we exclude them
in filtered decks in -is:suspended
Sibling spacing changes:
- core behaviour now based on automatically burying related cards when we
answer a card
- applies to reviews, optionally to new cards, and never to cards in the
learning queue (partly because we can't suspend/bury cards in that queue at
the moment)
- this means spacing works consistently in filtered decks now, works on
reviews even when user is late to review, and provides better separation of
new cards
- if burying new cards disabled, we just discard them from the current queue.
an option to set due=ord*space+due would be nicer, but would require
changing a lot of code and is more appropriate for a future major version
change. discarding from queue suffers from the same issue as the new card
cycling in that queue rebuilds may cause cards to be shown close together,
so the default burying behaviour is preferable
- refer to them as 'related cards' rather than 'siblings'
These changes don't require any changes to the database format, so they
should hopefully coexist with older clients without issue.
2013-08-10 08:54:33 +02:00
|
|
|
if self.mw.col.sched.haveBuried():
|
|
|
|
links.append(["U", "unbury", _("Unbury")])
|
2012-12-21 08:51:59 +01:00
|
|
|
buf = ""
|
|
|
|
for b in links:
|
|
|
|
if b[0]:
|
|
|
|
b[0] = _("Shortcut key: %s") % shortcut(b[0])
|
|
|
|
buf += """
|
2019-12-23 01:34:10 +01:00
|
|
|
<button title="%s" onclick='pycmd("%s")'>%s</button>""" % tuple(
|
|
|
|
b
|
|
|
|
)
|
2020-02-12 22:00:13 +01:00
|
|
|
self.bottom.draw(
|
|
|
|
buf=buf, link_handler=self._linkHandler, web_context=OverviewBottomBar(self)
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Studying more
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
def onStudyMore(self):
|
|
|
|
import aqt.customstudy
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
aqt.customstudy.CustomStudy(self.mw)
|