From 6ddc276d57de297e6fcb57ad68e55abbea5c4dc4 Mon Sep 17 00:00:00 2001 From: Andreas Klauer Date: Mon, 25 Feb 2013 22:03:55 +0100 Subject: [PATCH] workaround for filter tree onclick not working (#729) --- aqt/browser.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/aqt/browser.py b/aqt/browser.py index 53b2fc456..e5e88c74b 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -683,8 +683,8 @@ by clicking on one on the left.""")) ###################################################################### class CallbackItem(QTreeWidgetItem): - def __init__(self, name, onclick): - QTreeWidgetItem.__init__(self, [name]) + def __init__(self, root, name, onclick): + QTreeWidgetItem.__init__(self, root, [name]) self.onclick = onclick def setupTree(self): @@ -698,7 +698,7 @@ by clicking on one on the left.""")) def buildTree(self): self.form.tree.clear() - root = self.form.tree.invisibleRootItem() + root = self.form.tree self._systemTagTree(root) self._decksTree(root) self._modelTree(root) @@ -752,9 +752,8 @@ by clicking on one on the left.""")) (_("Leech"), "emblem-important.png", "tag:leech")) for name, icon, cmd in tags: item = self.CallbackItem( - name, lambda c=cmd: self.setFilter(c)) + root, name, lambda c=cmd: self.setFilter(c)) item.setIcon(0, QIcon(":/icons/" + icon)) - root.addChild(item) return root def _userTagTree(self, root): @@ -762,19 +761,17 @@ by clicking on one on the left.""")) if t.lower() == "marked" or t.lower() == "leech": continue 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")) - root.addChild(item) def _decksTree(self, root): grps = self.col.sched.deckDueTree() def fillGroups(root, grps, head=""): for g in grps: item = self.CallbackItem( - g[0], lambda g=g: self.setFilter( - "deck", head+g[0])) + root, g[0], lambda g=g: self.setFilter( + "deck", head+g[0])) item.setIcon(0, QIcon(":/icons/deck16.png")) - root.addChild(item) newhead = head + g[0]+"::" fillGroups(item, g[5], newhead) fillGroups(root, grps) @@ -782,9 +779,8 @@ by clicking on one on the left.""")) def _modelTree(self, root): for m in sorted(self.col.models.all(), key=itemgetter("name")): 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")) - root.addChild(mitem) # for t in m['tmpls']: # titem = self.CallbackItem( # t['name'], lambda m=m, t=t: self.setFilter(