def createToggleCategoryFilterCommands(self, categories): categories = list(categories) categories.sort(key=lambda category: category.subject()) commands = [uicommand.ToggleCategoryFilter(category=category) for category in categories] categoriesWithChildren = [category for category in categories if category.children()] if categoriesWithChildren: commands.append(None) for category in categoriesWithChildren: subCommands = [_('%s (subcategories)')%category.subject()] subCommands.extend(self.createToggleCategoryFilterCommands(category.children())) commands.append(tuple(subCommands)) return commands
def addMenuItemsForCategories(self, categories, menu): categories = categories[:] categories.sort(key=lambda category: category.subject()) for category in categories: uiCommand = uicommand.ToggleCategory(category=category, viewer=self.viewer) uiCommand.addToMenu(menu, self._window) categoriesWithChildren = [category for category in categories if category.children()] if categoriesWithChildren: menu.AppendSeparator() for category in categoriesWithChildren: subMenu = wx.Menu() self.addMenuItemsForCategories(category.children(), subMenu) menu.AppendSubMenu(subMenu, self.subMenuLabel(category))
def addMenuItemsForCategories(self, categories, menu): # pylint: disable=W0621 categories = categories[:] categories.sort(key=lambda category: category.subject().lower()) for category in categories: uiCommand = uicommand.ToggleCategory(category=category, viewer=self.viewer) uiCommand.addToMenu(menu, self._window) categoriesWithChildren = [category for category in categories if category.children()] if categoriesWithChildren: menu.AppendSeparator() for category in categoriesWithChildren: subMenu = Menu(self._window) self.addMenuItemsForCategories(category.children(), subMenu) menu.AppendSubMenu(subMenu, self.subMenuLabel(category))
def addMenuItemsForCategories(self, categories, menu): categories = categories[:] categories.sort(key=lambda category: category.subject()) for category in categories: uiCommand = self.uiCommandClass(category=category, viewer=self.viewer) uiCommand.addToMenu(menu, self._window) categoriesWithChildren = [ category for category in categories if category.children() ] if categoriesWithChildren: menu.AppendSeparator() for category in categoriesWithChildren: subMenu = wx.Menu() self.addMenuItemsForCategories(category.children(), subMenu) menu.AppendSubMenu(subMenu, self.subMenuLabel(category))
def getCategoryWithIndex(self, index): children = self.__categories.rootItems() for i in index: category = children[i] childIndices = [ self.__categories.index(child) for child in category.children() if child in self.__categories ] childIndices.sort() children = [self.__categories[childIndex] for childIndex in childIndices] return category
def getChildrenCount(self, index): # FIXME: duplication with viewers if index == (): return len(self.__categories.rootItems()) else: category = self.getCategoryWithIndex(index) return len(category.children())