def _deckFilters26(self): def addDecks(parent, decks): for head, did, rev, lrn, new, children in decks: name = self.mw.col.decks.get(did)["name"] shortname = DeckManager.basename(name) if children: subm = parent.addMenu(shortname) subm.addItem(_("Filter"), self._filterFunc("deck", name)) subm.addSeparator() addDecks(subm, children) else: if did != 1 or self.col.decks.should_default_be_displayed( force_default=False, assume_no_child=True ): parent.addItem(shortname, self._filterFunc("deck", name)) # fixme: could rewrite to avoid calculating due # in the future alldecks = self.col.sched.deckDueTree() ml = MenuList() addDecks(ml, alldecks) root = SubMenu(_("Decks")) root.addChild(ml.chunked()) return root
def _tagFilters(self): m = SubMenu(_("Tags")) # m.addItem(_("Clear Unused"), self.clearUnusedTags) # m.addSeparator() tagList = MenuList() for t in sorted(self.col.tags.all(), key=lambda s: s.lower()): tagList.addItem(t, self._filterFunc("tag", t)) m.addChild(tagList.chunked()) return m
def _deckFilters28(self): def addDecks(parent, decks, parent_prefix): for node in decks: fullname = parent_prefix + node.name if node.children: subm = parent.addMenu(node.name) subm.addItem(_("Filter"), lambda: self._filterFunc("deck", fullname)) subm.addSeparator() addDecks(subm, node.children, fullname + "::") else: parent.addItem(node.name, self._filterFunc("deck", fullname)) alldecks = self.col.decks.deck_tree() ml = MenuList() addDecks(ml, alldecks.children, "") root = SubMenu(_("Decks")) root.addChild(ml.chunked()) return root
def _noteTypeFilters(self): m = SubMenu(_("Note Types")) m.addItem(_("Manage..."), self.mw.onNoteTypes) m.addSeparator() noteTypes = MenuList() for nt in sorted(self.col.models.all(), key=lambda nt: nt["name"].lower()): # no sub menu if it's a single template if len(nt["tmpls"]) == 1: noteTypes.addItem(nt["name"], self._filterFunc("note", nt["name"])) else: subm = noteTypes.addMenu(nt["name"]) subm.addItem(_("All Card Types"), self._filterFunc("note", nt["name"])) subm.addSeparator() # add templates for c, tmpl in enumerate(nt["tmpls"]): # T: name is a card type name. n it's order in the list of card type. # T: this is shown in browser's filter, when seeing the list of card type of a note type. name = _("%(n)d: %(name)s") % dict(n=c + 1, name=tmpl["name"]) subm.addItem( name, self._filterFunc("note", nt["name"], "card", str(c + 1)) ) m.addChild(noteTypes.chunked()) return m
def _simpleFilters(self, items): ml = MenuList() for row in items: if row is None: ml.addSeparator() else: label, filter = row ml.addItem(label, self._filterFunc(filter)) return ml
def _savedSearches(self): ml = MenuList() # make sure exists if "savedFilters" not in self.col.conf: self.col.set_config("savedFilters", {}) ml.addSeparator() # if self._currentFilterIsSaved(): # ml.addItem(_("Remove Current Filter..."), self._onRemoveFilter) # else: # ml.addItem(_("Save Current Filter..."), self._onSaveFilter) saved = self.col.get_config("savedFilters") if not saved: return ml ml.addSeparator() for name, filt in sorted(saved.items()): ml.addItem(name, self._filterFunc(filt)) return ml
def __init__(self, parent, browser, func_gettext, func_settext): self.mw = browser.mw self.parent = parent self.col = browser.col self.func_gettext = func_gettext self.func_settext = func_settext ml = MenuList() ml.addChild(self._commonFilters()) ml.addSeparator() ml.addChild(self._todayFilters()) ml.addChild(self._cardStateFilters()) ml.addChild(self._deckFilters()) ml.addChild(self._noteTypeFilters()) ml.addChild(self._tagFilters()) ml.addSeparator() # ml.addChild(self.sidebarDockWidget.toggleViewAction()) ml.addSeparator() ml.addChild(self._savedSearches()) ml.popupOver(parent.form.pb_filter)