From 2e10fd115b7181d0616dd168184b986f25e578bf Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 16 Oct 2010 15:21:36 +0100 Subject: [PATCH 1/2] Put the icon file map into field metadata, then change tag_view to use it. --- src/calibre/gui2/tag_view.py | 18 ++++++------------ src/calibre/library/field_metadata.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index 3505cc7344..6e0aef1b99 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -17,7 +17,7 @@ from PyQt4.Qt import Qt, QTreeView, QApplication, pyqtSignal, \ from calibre.ebooks.metadata import title_sort from calibre.gui2 import config, NONE -from calibre.library.field_metadata import TagsIcons +from calibre.library.field_metadata import TagsIcons, category_icon_map from calibre.utils.search_query_parser import saved_searches from calibre.gui2 import error_dialog from calibre.gui2.dialogs.confirm_delete import confirm @@ -382,17 +382,11 @@ class TagsModel(QAbstractItemModel): # {{{ # must do this here because 'QPixmap: Must construct a QApplication # before a QPaintDevice'. The ':' in front avoids polluting either the # user-defined categories (':' at end) or columns namespaces (no ':'). - self.category_icon_map = TagsIcons({ - 'authors' : QIcon(I('user_profile.png')), - 'series' : QIcon(I('series.png')), - 'formats' : QIcon(I('book.png')), - 'publisher' : QIcon(I('publisher.png')), - 'rating' : QIcon(I('rating.png')), - 'news' : QIcon(I('news.png')), - 'tags' : QIcon(I('tags.png')), - ':custom' : QIcon(I('column.png')), - ':user' : QIcon(I('drawer.png')), - 'search' : QIcon(I('search.png'))}) + iconmap = {} + for key in category_icon_map: + iconmap[key] = QIcon(I(category_icon_map[key])) + self.category_icon_map = TagsIcons(iconmap) + self.categories_with_ratings = ['authors', 'series', 'publisher', 'tags'] self.drag_drop_finished = drag_drop_finished diff --git a/src/calibre/library/field_metadata.py b/src/calibre/library/field_metadata.py index 69dd7ae636..dbc871026e 100644 --- a/src/calibre/library/field_metadata.py +++ b/src/calibre/library/field_metadata.py @@ -22,6 +22,20 @@ class TagsIcons(dict): raise ValueError('Missing category icon [%s]'%a) self[a] = icon_dict[a] +category_icon_map = { + 'authors' : 'user_profile.png', + 'series' : 'series.png', + 'formats' : 'book.png', + 'publisher' : 'publisher.png', + 'rating' : 'rating.png', + 'news' : 'news.png', + 'tags' : 'tags.png', + ':custom' : 'column.png', + ':user' : 'drawer.png', + 'search' : 'search.png' + } + + class FieldMetadata(dict): ''' key: the key to the dictionary is: From 8a6e6c07e7b1d9edee0cc1aa9c775849d9e544aa Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 16 Oct 2010 15:28:25 +0100 Subject: [PATCH 2/2] Get the icons --- src/calibre/library/server/browse.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py index dc8494dc13..e4d001c959 100644 --- a/src/calibre/library/server/browse.py +++ b/src/calibre/library/server/browse.py @@ -18,6 +18,7 @@ from calibre.utils.filenames import ascii_filename from calibre.utils.config import prefs from calibre.library.comments import comments_to_html from calibre.library.server import custom_fields_to_display +from calibre.library.field_metadata import category_icon_map def render_book_list(ids, suffix=''): # {{{ pages = [] @@ -279,6 +280,16 @@ class BrowseServer(object): continue if meta['is_custom'] and category not in displayed_custom_fields: continue + # get the icon files + if category in category_icon_map: + icon = I(category_icon_map[category]) + elif meta['is_custom']: + icon = I(category_icon_map[':custom']) + elif meta['kind'] == 'user': + icon = I(category_icon_map[':user']) + else: + icon = None # shouldn't get here + cats.append((meta['name'], category)) cats = ['