From 1344d5a702734682dbd64457d015322be2ba6bcd Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 18 Feb 2012 14:34:38 +0100 Subject: [PATCH] Add the ability to control the order of categories in the tag browser --- resources/default_tweaks.py | 11 +++++++++++ src/calibre/gui2/tag_browser/model.py | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index d920f6c98c..b35cb79729 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -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_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 # Provide a set of columns to be sorted on when calibre starts # The argument is None if saved sort history is to be used diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index 047ae687ae..517772fef8 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -831,7 +831,11 @@ class TagsModel(QAbstractItemModel): # {{{ if lower(t.name).find(self.filter_categories_by) >= 0] tb_categories = self.db.field_metadata - for category in tb_categories: + tb_keys = tb_categories.keys() + tb_keys.sort(key=lambda x, + y=tweaks['tag_browser_category_order']: + y[x] if x in y else y['*'] if '*' in y else 100) + for category in tb_keys: if category in data: # The search category can come and go self.row_map.append(category) self.categories[category] = tb_categories[category]['name']