def userTagTree(browser, root): assert browser.col tree=browser.sidebarTree ico = ":/icons/tag.svg" getConfig = getConfigGetterMethod() showConf = getConfig('Blitzkrieg.showAllTags', True) icoOpt = getConfig('Blitzkrieg.icon_tag',True) rootNode = SidebarItem( "Tags", ico, expanded=tree.node_state.get("group").get('tag',True) ) rootNode.type = "group" rootNode.fullname = "tag" root.addChild(rootNode) tags_tree = {} SORT = getConfig('Blitzkrieg.sort_tag',False) TAGS = sorted(browser.col.tags.all(), key=lambda t: t.lower() if SORT else t) for t in TAGS: if t.lower() == "marked" or t.lower() == "leech": continue node = t.split('::') lstIdx = len(node)-1 for idx, name in enumerate(node): leaf_tag = '::'.join(node[0:idx + 1]) if not tags_tree.get(leaf_tag): parent = tags_tree['::'.join(node[0:idx])] if idx else rootNode exp = tree.node_state.get('tag').get(leaf_tag,False) if showConf: fil = f'("tag:{leaf_tag}" or "tag:{leaf_tag}::*")' click = browser._filterFunc(fil) else: click = browser._filterFunc("tag", leaf_tag) item = SidebarItem( name, ico if icoOpt or idx==lstIdx else None, click, expanded=exp ) parent.addChild(item) item.type = "tag" item.fullname = leaf_tag if tree.found.get(item.type,{}).get(leaf_tag, False): item.background=QBrush(Qt.cyan) elif tree.marked['tag'].get(leaf_tag, False): item.background=QBrush(Qt.yellow) elif exp and '::' not in leaf_tag: item.background=QBrush(QColor(0,0,10,10)) tags_tree[leaf_tag] = item tag_cnt = len(TAGS) rootNode.tooltip = f"Total: {tag_cnt} tags"
def modelTree(browser, root): assert browser.col tree=browser.sidebarTree ico = ":/icons/notetype.svg" getConfig = getConfigGetterMethod() icoOpt = getConfig('Blitzkrieg.icon_model',True) rootNode = SidebarItem( _("Models"), ico, expanded=tree.node_state.get("group").get('model',False) ) rootNode.type = "group" rootNode.fullname = "model" root.addChild(rootNode) models_tree = {} SORT = getConfig('Blitzkrieg.sort_model',False) MODELS = sorted(browser.col.models.all(), key=lambda m: m["name"].lower() if SORT else m["name"]) for m in MODELS: item = None mid=str(m['id']) node = m['name'].split('::') lstIdx = len(node)-1 for idx, name in enumerate(node): leaf_model = '::'.join(node[0:idx + 1]) if not models_tree.get(leaf_model) or idx==lstIdx: #last element, model names are not unique parent = models_tree['::'.join(node[0:idx])] if idx else rootNode exp = tree.node_state.get('model').get(leaf_model,False) item = SidebarItem( name, ico if icoOpt or idx==lstIdx else None, browser._filterFunc("mid", str(m['id'])), expanded=exp ) parent.addChild(item) item.type = "model" item.fullname = leaf_model item.mid = mid if tree.found.get(item.type,{}).get(leaf_model, False): item.background=QBrush(Qt.cyan) elif tree.marked['model'].get(leaf_model, False): item.background=QBrush(Qt.yellow) models_tree[leaf_model] = item model_cnt = len(MODELS) rootNode.tooltip = f"Total: {model_cnt} models"
def decksTree(browser, root): assert browser.col tree=browser.sidebarTree ico = ":/icons/deck.svg" rootNode = SidebarItem( _("Decks"), ico, expanded=tree.node_state.get("group").get('deck',True) ) rootNode.type = "group" rootNode.fullname = "deck" root.addChild(rootNode) getConfig = getConfigGetterMethod() SORT = getConfig('Blitzkrieg.sort_deck',False) grps = sorted(browser.col.sched.deckDueTree(), key=lambda g: g[0].lower() if SORT else g[0]) def fillGroups(rootNode, grps, head=""): for g in grps: item = SidebarItem( g[0], ico, lambda g=g: browser.setFilter("deck", head+g[0]), lambda expanded, g=g: browser.mw.col.decks.collapseBrowser(g[1]), not browser.mw.col.decks.get(g[1]).get('browserCollapsed', False)) rootNode.addChild(item) item.fullname = head + g[0] #name if mw.col.decks.isDyn(g[1]): #id item.foreground = QBrush(Qt.blue) item.type = "dyn" else: if g[1]==1: #default deck item.foreground = QBrush(Qt.darkRed) item.type = "deck" if tree.found.get(item.type,{}).get(item.fullname, False): item.background=QBrush(Qt.cyan) elif tree.marked[item.type].get(item.fullname, False): item.background=QBrush(Qt.yellow) newhead = head + g[0]+"::" fillGroups(item, g[5], newhead) fillGroups(rootNode, grps) deck_cnt = len(browser.col.decks.all()) rootNode.tooltip = f"Total: {deck_cnt} decks"