mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
/browse: Icons for top level
This commit is contained in:
commit
b54e07402e
@ -192,7 +192,6 @@ h2.library_name {
|
||||
.toplevel li {
|
||||
margin: 0.75em;
|
||||
padding: 0.75em;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border-radius: 15px;
|
||||
-moz-border-radius: 15px;
|
||||
@ -200,6 +199,10 @@ h2.library_name {
|
||||
|
||||
}
|
||||
|
||||
.toplevel li img {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.toplevel li:hover {
|
||||
background-color: #d6d3c9;
|
||||
font-weight: bold;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -16,8 +16,10 @@ from calibre import isbytestring, force_unicode, prepare_string_for_xml as xml
|
||||
from calibre.utils.ordered_dict import OrderedDict
|
||||
from calibre.utils.filenames import ascii_filename
|
||||
from calibre.utils.config import prefs
|
||||
from calibre.utils.magick import Image
|
||||
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 = []
|
||||
@ -192,6 +194,8 @@ class BrowseServer(object):
|
||||
self.browse_search)
|
||||
connect('browse_details', base_href+'/details/{id}',
|
||||
self.browse_details)
|
||||
connect('browse_category_icon', base_href+'/icon/{name}',
|
||||
self.browse_icon)
|
||||
|
||||
# Templates {{{
|
||||
def browse_template(self, sort, category=True, initial_search=''):
|
||||
@ -257,11 +261,24 @@ class BrowseServer(object):
|
||||
# }}}
|
||||
|
||||
# Catalogs {{{
|
||||
def browse_icon(self, name='blank.png'):
|
||||
try:
|
||||
data = I(name, data=True)
|
||||
except:
|
||||
raise cherrypy.HTTPError(404, 'no icon named: %r'%name)
|
||||
img = Image()
|
||||
img.load(data)
|
||||
img.size = (48, 48)
|
||||
cherrypy.response.headers['Content-Type'] = 'image/png'
|
||||
cherrypy.response.headers['Last-Modified'] = self.last_modified(self.build_time)
|
||||
|
||||
return img.export('png')
|
||||
|
||||
def browse_toplevel(self):
|
||||
categories = self.categories_cache()
|
||||
category_meta = self.db.field_metadata
|
||||
cats = [
|
||||
(_('Newest'), 'newest'),
|
||||
(_('Newest'), 'newest', 'blank.png'),
|
||||
]
|
||||
|
||||
def getter(x):
|
||||
@ -279,10 +296,22 @@ class BrowseServer(object):
|
||||
continue
|
||||
if meta['is_custom'] and category not in displayed_custom_fields:
|
||||
continue
|
||||
cats.append((meta['name'], category))
|
||||
cats = ['<li title="{2} {0}">{0}<span>/browse/category/{1}</span></li>'\
|
||||
.format(xml(x, True), xml(quote(y)), xml(_('Browse books by')))
|
||||
for x, y in cats]
|
||||
# get the icon files
|
||||
if category in category_icon_map:
|
||||
icon = category_icon_map[category]
|
||||
elif meta['is_custom']:
|
||||
icon = category_icon_map[':custom']
|
||||
elif meta['kind'] == 'user':
|
||||
icon = category_icon_map[':user']
|
||||
else:
|
||||
icon = 'blank.png'
|
||||
cats.append((meta['name'], category, icon))
|
||||
|
||||
cats = [('<li title="{2} {0}"><img src="{src}" alt="{0}" /> {0}'
|
||||
'<span>/browse/category/{1}</span></li>')
|
||||
.format(xml(x, True), xml(quote(y)), xml(_('Browse books by')),
|
||||
src='/browse/icon/'+z)
|
||||
for x, y, z in cats]
|
||||
|
||||
main = '<div class="toplevel"><h3>{0}</h3><ul>{1}</ul></div>'\
|
||||
.format(_('Choose a category to browse by:'), '\n\n'.join(cats))
|
||||
|
Loading…
x
Reference in New Issue
Block a user