Add a tweak to Preferences->Tweaks to control the order in which categories appear in the Tag Browser

This commit is contained in:
Kovid Goyal 2012-02-19 00:03:32 +05:30
commit 2653da4ecf
2 changed files with 18 additions and 1 deletions

View File

@ -128,6 +128,17 @@ categories_collapsed_name_template = r'{first.sort:shorten(4,,0)} - {last.sort:s
categories_collapsed_rating_template = r'{first.avg_rating:4.2f:ifempty(0)} - {last.avg_rating:4.2f:ifempty(0)}' categories_collapsed_rating_template = r'{first.avg_rating:4.2f:ifempty(0)} - {last.avg_rating:4.2f:ifempty(0)}'
categories_collapsed_popularity_template = r'{first.count:d} - {last.count:d}' categories_collapsed_popularity_template = r'{first.count:d} - {last.count:d}'
#: Control order of categories in the tag browser
# Change the following dict to change the order that categories are displayed in
# the tag browser. Items are named using their lookup name, and will be sorted
# using the number supplied. The lookup name '*' stands for all names that
# otherwise do not appear. Two names with the same value will be sorted
# according the the default order; the one used when the dict is empty.
# Example: tag_browser_category_order = {'series':1, 'tags':2, '*':3}
# resulting in the order series, tags, then everything else in default order.
tag_browser_category_order = {'*':1}
#: Specify columns to sort the booklist by on startup #: Specify columns to sort the booklist by on startup
# Provide a set of columns to be sorted on when calibre starts # Provide a set of columns to be sorted on when calibre starts
# The argument is None if saved sort history is to be used # The argument is None if saved sort history is to be used

View File

@ -10,6 +10,7 @@ __docformat__ = 'restructuredtext en'
import traceback, cPickle, copy import traceback, cPickle, copy
from itertools import repeat from itertools import repeat
from collections import defaultdict
from PyQt4.Qt import (QAbstractItemModel, QIcon, QVariant, QFont, Qt, from PyQt4.Qt import (QAbstractItemModel, QIcon, QVariant, QFont, Qt,
QMimeData, QModelIndex, pyqtSignal, QObject) QMimeData, QModelIndex, pyqtSignal, QObject)
@ -831,7 +832,12 @@ class TagsModel(QAbstractItemModel): # {{{
if lower(t.name).find(self.filter_categories_by) >= 0] if lower(t.name).find(self.filter_categories_by) >= 0]
tb_categories = self.db.field_metadata tb_categories = self.db.field_metadata
for category in tb_categories: y = tweaks['tag_browser_category_order']
deforder = y.get('*', 100)
order = defaultdict(lambda : deforder)
order.update(y)
tb_keys = sorted(tb_categories.iterkeys(), key=lambda x: order[x])
for category in tb_keys:
if category in data: # The search category can come and go if category in data: # The search category can come and go
self.row_map.append(category) self.row_map.append(category)
self.categories[category] = tb_categories[category]['name'] self.categories[category] = tb_categories[category]['name']