Merge branch 'master' of github.com:dae/anki

This commit is contained in:
Damien Elmes 2013-02-26 19:11:56 +09:00
commit c8d3d5a337

View File

@ -683,8 +683,8 @@ by clicking on one on the left."""))
###################################################################### ######################################################################
class CallbackItem(QTreeWidgetItem): class CallbackItem(QTreeWidgetItem):
def __init__(self, name, onclick): def __init__(self, root, name, onclick):
QTreeWidgetItem.__init__(self, [name]) QTreeWidgetItem.__init__(self, root, [name])
self.onclick = onclick self.onclick = onclick
def setupTree(self): def setupTree(self):
@ -698,7 +698,7 @@ by clicking on one on the left."""))
def buildTree(self): def buildTree(self):
self.form.tree.clear() self.form.tree.clear()
root = self.form.tree.invisibleRootItem() root = self.form.tree
self._systemTagTree(root) self._systemTagTree(root)
self._decksTree(root) self._decksTree(root)
self._modelTree(root) self._modelTree(root)
@ -752,9 +752,8 @@ by clicking on one on the left."""))
(_("Leech"), "emblem-important.png", "tag:leech")) (_("Leech"), "emblem-important.png", "tag:leech"))
for name, icon, cmd in tags: for name, icon, cmd in tags:
item = self.CallbackItem( item = self.CallbackItem(
name, lambda c=cmd: self.setFilter(c)) root, name, lambda c=cmd: self.setFilter(c))
item.setIcon(0, QIcon(":/icons/" + icon)) item.setIcon(0, QIcon(":/icons/" + icon))
root.addChild(item)
return root return root
def _userTagTree(self, root): def _userTagTree(self, root):
@ -762,19 +761,17 @@ by clicking on one on the left."""))
if t.lower() == "marked" or t.lower() == "leech": if t.lower() == "marked" or t.lower() == "leech":
continue continue
item = self.CallbackItem( item = self.CallbackItem(
t, lambda t=t: self.setFilter("tag", t)) root, t, lambda t=t: self.setFilter("tag", t))
item.setIcon(0, QIcon(":/icons/anki-tag.png")) item.setIcon(0, QIcon(":/icons/anki-tag.png"))
root.addChild(item)
def _decksTree(self, root): def _decksTree(self, root):
grps = self.col.sched.deckDueTree() grps = self.col.sched.deckDueTree()
def fillGroups(root, grps, head=""): def fillGroups(root, grps, head=""):
for g in grps: for g in grps:
item = self.CallbackItem( item = self.CallbackItem(
g[0], lambda g=g: self.setFilter( root, g[0], lambda g=g: self.setFilter(
"deck", head+g[0])) "deck", head+g[0]))
item.setIcon(0, QIcon(":/icons/deck16.png")) item.setIcon(0, QIcon(":/icons/deck16.png"))
root.addChild(item)
newhead = head + g[0]+"::" newhead = head + g[0]+"::"
fillGroups(item, g[5], newhead) fillGroups(item, g[5], newhead)
fillGroups(root, grps) fillGroups(root, grps)
@ -782,9 +779,8 @@ by clicking on one on the left."""))
def _modelTree(self, root): def _modelTree(self, root):
for m in sorted(self.col.models.all(), key=itemgetter("name")): for m in sorted(self.col.models.all(), key=itemgetter("name")):
mitem = self.CallbackItem( mitem = self.CallbackItem(
m['name'], lambda m=m: self.setFilter("mid", str(m['id']))) root, m['name'], lambda m=m: self.setFilter("mid", str(m['id'])))
mitem.setIcon(0, QIcon(":/icons/product_design.png")) mitem.setIcon(0, QIcon(":/icons/product_design.png"))
root.addChild(mitem)
# for t in m['tmpls']: # for t in m['tmpls']:
# titem = self.CallbackItem( # titem = self.CallbackItem(
# t['name'], lambda m=m, t=t: self.setFilter( # t['name'], lambda m=m, t=t: self.setFilter(