# -*- coding: utf-8 -*- # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html from aqt.utils import openLink, shortcut, tooltip, askUserDialog import aqt from anki.sound import clearAudioQueue from anki.lang import _ class Overview: "Deck overview." def __init__(self, mw): self.mw = mw self.web = mw.web self.bottom = aqt.toolbar.BottomBar(mw, mw.bottomWeb) def show(self): clearAudioQueue() self.web.resetHandlers() self.web.onBridgeCmd = self._linkHandler self.mw.setStateShortcuts(self._shortcutKeys()) self.refresh() def refresh(self): self.mw.col.reset() self._renderPage() self._renderBottom() self.mw.web.setFocus() # Handlers ############################################################ def _linkHandler(self, url): if url == "study": self.mw.col.startTimebox() self.mw.moveToState("review") if self.mw.state == "overview": tooltip(_("No cards are due yet.")) elif url == "anki": print("anki menu") elif url == "opts": self.mw.onDeckConf() elif url == "cram": deck = self.mw.col.decks.current() self.mw.onCram("'deck:%s'" % deck['name']) 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": openLink(aqt.appShared+"info/%s?v=%s"%(self.sid, self.sidVer)) elif url == "studymore": self.onStudyMore() elif url == "unbury": self.onUnbury() elif url.lower().startswith("http"): openLink(url) return False def _shortcutKeys(self): return [ ("o", self.mw.onDeckConf), ("r", self.onRebuildKey), ("e", self.onEmptyKey), ("c", self.onCustomStudyKey), ("u", self.onUnbury) ] def _filteredDeck(self): return self.mw.col.decks.current()['dyn'] def onRebuildKey(self): if self._filteredDeck(): self.mw.col.sched.rebuildDyn() self.mw.reset() def onEmptyKey(self): if self._filteredDeck(): self.mw.col.sched.emptyDyn(self.mw.col.decks.selected()) self.mw.reset() def onCustomStudyKey(self): if not self._filteredDeck(): self.onStudyMore() def onUnbury(self): if self.mw.col.schedVer() == 1: self.mw.col.sched.unburyCardsForDeck() self.mw.reset() return sibs = self.mw.col.sched.haveBuriedSiblings() man = self.mw.col.sched.haveManuallyBuried() if sibs and man: opts = [_("Manually Buried Cards"), _("Buried Siblings"), _("All Buried Cards"), _("Cancel")] 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") self.mw.reset() # 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 = 'Reviews and Updates' else: shareLink = "" self.web.stdHtml(self._body % dict( deck=deck['name'], shareLink=shareLink, desc=self._desc(deck), table=self._table() ), css=["overview.css"], js=["jquery.js", "overview.js"]) def _desc(self, deck): if deck['dyn']: desc = _("""\ This is a special deck for studying outside of the normal schedule.""") desc += " " + _("""\ Cards will be automatically returned to their original decks after you review \ them.""") desc += " " + _("""\ Deleting this deck from the deck list will return all remaining cards \ to their original deck.""") else: desc = deck.get("desc", "") if not desc: return "
" if deck['dyn']: dyn = "dyn" else: dyn = "" return '
| %s |