Ejemplo n.º 1
0
def stdTree(browser, root):
    for name, filt, icon in [[_("Whole Collection"), "", "collection"],
                       [_("Current Deck"), "deck:current", "deck"]]:
        item = SidebarItem(
            name, ":/icons/{}.svg".format(icon), browser._filterFunc(filt))
        item.type=None
        root.addChild(item)
Ejemplo n.º 2
0
def custom_modelTree_since_2_1_17(self, root, _old):
    types = SidebarItem(_("Note Types"), icon_notetype)
    for m in sorted(self.col.models.all(), key=itemgetter("name")):
        item = SidebarItem(
            m["name"],
            icon_notetype,
            lambda m=m: self.setFilter("note", m["name"]),  # type: ignore
        )
        types.addChild(item)
    root.addChild(types)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
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"
Ejemplo n.º 5
0
 def fillGroups(root, grps, head=""):
     for g in grps:
         item = SidebarItem(
             g[0],
             icon_deck,
             lambda g=g: self.setFilter("deck", head + g[0]),
             lambda expanded, g=g: self.mw.col.decks.collapseBrowser(g[1]),
             not self.mw.col.decks.get(g[1]).get("browserCollapsed", False),
         )
         root.addChild(item)
         newhead = head + g[0] + "::"
         fillGroups(item, g[5], newhead)
Ejemplo n.º 6
0
def favTree(browser, root):
    assert browser.col
    tree = browser.sidebarTree
    ico = ":/icons/heart.svg"

    getConfig = getConfigGetterMethod()

    icoOpt = getConfig('Blitzkrieg.icon_fav',True)

    saved = getConfig('savedFilters', {})
    if not saved:
        return
    favs_tree = {}
    for fav, filt in sorted(saved.items()):
        node = fav.split('::')
        lstIdx = len(node)-1
        ico = "heart.svg"
        type = "fav"
        fname = None
        for idx, name in enumerate(node):
            if node[0]=='Pinned':
                if idx==0:
                    type = "pin"
                elif filt.startswith('"tag:'):
                    type = "pinTag"
                    ico = "tag.svg"
                    fname = filt[5:-1]

                    # TODO: fix tags with () chars

                elif filt.startswith('"deck:'):
                    type = "pinDeck"
                    ico = "deck.svg"
                    fname = filt[6:-1]
                elif filt.startswith('"dyn:'):
                    type = "pinDyn"
                    ico = "deck.svg"
                    fname = filt[5:-1]
                    filt='"deck'+filt[4:]

            item = None
            leaf_tag = '::'.join(node[0:idx + 1])
            if not favs_tree.get(leaf_tag):
                parent = favs_tree['::'.join(node[0:idx])] if idx else root
                exp = tree.node_state.get(type).get(leaf_tag,False)
                item = SidebarItem(
                    name,
                    (":/icons/"+ico) if icoOpt or not idx or idx==lstIdx else None,
                    browser._filterFunc(filt),
                    expanded=exp
                )
                parent.addChild(item)

                item.type = type
                item.fullname = fname or leaf_tag
                item.favname = leaf_tag
                if tree.marked[type].get(leaf_tag, False):
                    item.background=QBrush(Qt.yellow)
                favs_tree[leaf_tag] = item
Ejemplo n.º 7
0
def userTagTree(self, root, _old):
    tags = sorted(self.col.tags.all())
    tags_tree = {}

    for t in tags:
        components = t.split(SEPARATOR)
        for idx, c in enumerate(components):
            partial_tag = SEPARATOR.join(components[0:idx + 1])
            if not tags_tree.get(partial_tag):
                if idx == 0:
                    parent = root
                else:
                    parent_tag = SEPARATOR.join(components[0:idx])
                    parent = tags_tree[parent_tag]

                item = SidebarItem(c, ":/icons/tag.svg")
                item.onClick = lambda i=item, t=partial_tag: self.onTagClick(
                    i, t)

                tags_tree[partial_tag] = item

                parent.addChild(item)
Ejemplo n.º 8
0
def custom_decksTree_since_2_1_17(self, root, _old):
    decks = SidebarItem(_("Decks"), icon_deck)
    grps = self.col.sched.deckDueTree()
    def fillGroups(root, grps, head=""):
        for g in grps:
            item = SidebarItem(
                g[0],
                icon_deck,
                lambda g=g: self.setFilter("deck", head + g[0]),
                lambda expanded, g=g: self.mw.col.decks.collapseBrowser(g[1]),
                not self.mw.col.decks.get(g[1]).get("browserCollapsed", False),
            )
            root.addChild(item)
            newhead = head + g[0] + "::"
            fillGroups(item, g[5], newhead)
    fillGroups(decks, grps)
    root.addChild(decks)
Ejemplo n.º 9
0
def replace_buildTree(self):
    global browserInstance
    browserInstance = self
    self.sidebarTree.browser = self

    root = SidebarItem("", "")

    try: #addons compatibility
        self._stdTree(root) #2.1.17++
    except TypeError:
        stdTree(self,root) #2.1.16--

    favTree(self,root)
    decksTree(self,root)
    modelTree(self,root)
    userTagTree(self,root)
    return root
Ejemplo n.º 10
0
def custom_stdTree_since_2_1_17(self, root):
    if config['show_item_marked']:
        item = SidebarItem(_("Marked"), icon_tag, self._filterFunc("tag:marked"))
        root.addChild(item)
    if config['show_item_suspended']:
        item = SidebarItem(_("Suspended"), icon_tag, self._filterFunc("is:suspended"))
        root.addChild(item)
    if config['show_item_leech']:
        item = SidebarItem(_("Leech"), icon_tag, self._filterFunc("tag:leech"))
        root.addChild(item)
    if config['show_tree_today']:
        today = SidebarItem(_("Today"), icon_tag)
        item = SidebarItem(_("Added Today"), "", self._filterFunc("added:1"))
        today.addChild(item)
        item = SidebarItem(_("Studied Today"), "", self._filterFunc("rated:1"))
        today.addChild(item)
        item = SidebarItem(_("Again Today"), "", self._filterFunc("rated:1:1"))
        today.addChild(item)
        root.addChild(today)
    if config['show_tree_flags']:
        flags = SidebarItem(_("Flags"), icon_tag)
        item = SidebarItem(_("Red"), "", self._filterFunc("flag:1"))
        flags.addChild(item)
        item = SidebarItem(_("Orange"), "", self._filterFunc("flag:2"))
        flags.addChild(item)
        item = SidebarItem(_("Green"), "", self._filterFunc("flag:3"))
        flags.addChild(item)
        item = SidebarItem(_("Blue"), "", self._filterFunc("flag:4"))
        flags.addChild(item)
        item = SidebarItem(_("No"), "", self._filterFunc("flag:0"))
        flags.addChild(item)
        item = SidebarItem(_("Any"), "", self._filterFunc("-flag:0"))
        flags.addChild(item)
        root.addChild(flags)
Ejemplo n.º 11
0
def custom_favTree_since_2_1_17(self, root, _old):
    favs = SidebarItem(_("My Filters"), icon_heart)
    for name, filt in sorted(self.col.conf.get('savedFilters', {}).items()):
        item = SidebarItem(name, icon_heart, lambda s=filt: self.setFilter(s))
        favs.addChild(item)
    root.addChild(favs)
Ejemplo n.º 12
0
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"
Ejemplo n.º 13
0
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"