/
sortSuspend.py
53 lines (43 loc) · 1.61 KB
/
sortSuspend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This plugin shows a replaces the "Suspend" menu entry in anki with a submenu,
# listing all suspended tags, so you can sort it.
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ankiqt import mw
from anki.utils import parseTags, addTags
def setTagCallable(tag):
def callable():
tagCurrentCard(tag)
return callable
def createTagsMenu():
mw.tagsMenu = QMenu("Suspend", mw)
mw.tagsMenu.setIcon(QIcon(":icons/media-playback-pause.png"))
mw.tagsMenu.setText = mw.tagsMenu.setTitle
updateMenu()
def updateMenu():
try:
mw.tagsMenu.clear()
for t in parseTags(mw.deck.suspended):
mw.tagsMenu.addAction(t, setTagCallable(t))
except AttributeError:
# mw.deck doesn't exist yet. wait for the menu to be invoked.
pass
def tagCurrentCard(tag):
mw.deck.setUndoStart(_("Suspend"))
mw.currentCard.fact.tags = addTags(tag, mw.currentCard.fact.tags)
mw.currentCard.fact.setModified()
for card in mw.currentCard.fact.cards:
mw.deck.updatePriority(card)
mw.deck.setModified()
mw.lastScheduledTime = None
mw.reset()
mw.deck.setUndoEnd(_("Suspend"))
def replaceMenu():
# create the new menu
createTagsMenu()
# insert it into the "current" menu
mw.mainWin.menuEdit.insertMenu(mw.mainWin.actionSuspendCard, mw.tagsMenu)
mw.mainWin.menuEdit.removeAction(mw.mainWin.actionSuspendCard)
# the app should do the same things to the menu as it would to the old button
mw.mainWin.actionSuspendCard = mw.tagsMenu
mw.connect(mw.tagsMenu, SIGNAL("aboutToShow()"), updateMenu)
mw.addHook("init", replaceMenu)