def show_details(self, index): f = rating_font() book = self.model().data(index, Qt.UserRole) parts = [ '<center>', '<h2>%s</h2>'%book.title, '<div><i>%s</i></div>'%authors_to_string(book.authors), ] if not book.is_null('series'): series = book.format_field('series') if series[1]: parts.append('<div>%s: %s</div>'%series) if not book.is_null('rating'): style = 'style=\'font-family:"%s"\''%f parts.append('<div %s>%s</div>'%(style, '\u2605'*int(book.rating))) parts.append('</center>') if book.identifiers: urls = urls_from_identifiers(book.identifiers) ids = ['<a href="%s">%s</a>'%(url, name) for name, ign, ign, url in urls] if ids: parts.append('<div><b>%s:</b> %s</div><br>'%(_('See at'), ', '.join(ids))) if book.tags: parts.append('<div>%s</div><div>\u00a0</div>'%', '.join(book.tags)) if book.comments: parts.append(comments_to_html(book.comments)) self.show_details_signal.emit(''.join(parts))
def show_details(self, index): f = rating_font() book = self.model().data(index, Qt.UserRole) parts = [ '<center>', '<h2>%s</h2>' % book.title, '<div><i>%s</i></div>' % authors_to_string(book.authors), ] if not book.is_null('series'): series = book.format_field('series') if series[1]: parts.append('<div>%s: %s</div>' % series) if not book.is_null('rating'): style = 'style=\'font-family:"%s"\'' % f parts.append('<div %s>%s</div>' % (style, '\u2605' * int(book.rating))) parts.append('</center>') if book.identifiers: urls = urls_from_identifiers(book.identifiers) ids = [ '<a href="%s">%s</a>' % (url, name) for name, ign, ign, url in urls ] if ids: parts.append('<div><b>%s:</b> %s</div><br>' % (_('See at'), ', '.join(ids))) if book.tags: parts.append('<div>%s</div><div>\u00a0</div>' % ', '.join(book.tags)) if book.comments: parts.append(comments_to_html(book.comments)) self.show_details_signal.emit(''.join(parts))
def render_data(mi, use_roman_numbers=True, all_fields=False, pref_name='book_display_fields'): field_list = get_field_list(getattr(mi, 'field_metadata', field_metadata), pref_name=pref_name) field_list = [(x, all_fields or display) for x, display in field_list] return mi_to_html( mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rtl=is_rtl(), rating_font=rating_font(), default_author_link=default_author_link(), comments_heading_pos=gprefs['book_details_comments_heading_pos'], for_qt=True )
def render_data(mi, use_roman_numbers=True, all_fields=False): field_list = get_field_list(getattr(mi, 'field_metadata', field_metadata)) field_list = [(x, all_fields or display) for x, display in field_list] return mi_to_html(mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rating_font=rating_font(), default_author_link=gprefs.get('default_author_link'))
def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args, **kwargs) self.rf = QFont(rating_font()) self.em = Qt.ElideMiddle delta = 0 if iswindows and sys.getwindowsversion().major >= 6: delta = 2 self.rf.setPointSize(QFontInfo(QApplication.font()).pointSize()+delta)
def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args, **kwargs) self.rf = QFont(rating_font()) self.em = Qt.ElideMiddle delta = 0 if iswindows and sys.getwindowsversion().major >= 6: delta = 2 self.rf.setPointSize(QFontInfo(QApplication.font()).pointSize()+delta)
def render_data(mi, use_roman_numbers=True, all_fields=False, pref_name='book_display_fields'): return mi_to_html(mi, use_roman_numbers=use_roman_numbers, rating_font=rating_font(), rtl=is_rtl(), default_author_link=default_author_link())
def render_data(mi, use_roman_numbers=True, all_fields=False): field_list = get_field_list(getattr(mi, "field_metadata", field_metadata)) field_list = [(x, all_fields or display) for x, display in field_list] return mi_to_html( mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rating_font=rating_font(), default_author_link=gprefs.get("default_author_link"), )
def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args) self.is_half_star = kwargs.get('is_half_star', False) self.table_widget = args[0] self.rf = QFont(rating_font()) self.em = Qt.TextElideMode.ElideMiddle delta = 0 if iswindows and sys.getwindowsversion().major >= 6: delta = 2 self.rf.setPointSize(QFontInfo(QApplication.font()).pointSize()+delta)
def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args, **kwargs) self.is_half_star = kwargs.get('is_half_star', False) self.table_widget = args[0] self.rf = QFont(rating_font()) self.em = Qt.ElideMiddle delta = 0 if iswindows and sys.getwindowsversion().major >= 6: delta = 2 self.rf.setPointSize(QFontInfo(QApplication.font()).pointSize()+delta)
def __init__(self, parent=None): pictureflow.PictureFlow.__init__(self, parent, config["cover_flow_queue_length"] + 1) self.setMinimumSize(QSize(300, 150)) self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.dc_signal.connect(self._data_changed, type=Qt.QueuedConnection) self.context_menu = None self.setContextMenuPolicy(Qt.DefaultContextMenu) self.setPreserveAspectRatio(gprefs["cb_preserve_aspect_ratio"]) self.setSubtitleFont(QFont(rating_font())) if not gprefs["cover_browser_reflections"]: self.setShowReflections(False)
def __init__(self, parent): super(CoverDelegate, self).__init__(parent) self._animated_size = 1.0 self.animation = QPropertyAnimation(self, b'animated_size', self) self.animation.setEasingCurve(QEasingCurve.OutInCirc) self.animation.setDuration(500) self.set_dimensions() self.cover_cache = CoverCache() self.render_queue = LifoQueue() self.animating = None self.highlight_color = QColor(Qt.white) self.rating_font = QFont(rating_font())
def __init__(self, parent): super(CoverDelegate, self).__init__(parent) self._animated_size = 1.0 self.animation = QPropertyAnimation(self, b'animated_size', self) self.animation.setEasingCurve(QEasingCurve.OutInCirc) self.animation.setDuration(500) self.set_dimensions() self.cover_cache = CoverCache() self.render_queue = LifoQueue() self.animating = None self.highlight_color = QColor(Qt.white) self.rating_font = QFont(rating_font())
def __init__(self, parent=None): pictureflow.PictureFlow.__init__(self, parent, config['cover_flow_queue_length']+1) self.setMinimumSize(QSize(300, 150)) self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.dc_signal.connect(self._data_changed, type=Qt.QueuedConnection) self.context_menu = None self.setContextMenuPolicy(Qt.DefaultContextMenu) if hasattr(self, 'setSubtitleFont'): self.setSubtitleFont(QFont(rating_font()))
def __init__(self, parent=None): pictureflow.PictureFlow.__init__( self, parent, config['cover_flow_queue_length'] + 1) self.setMinimumSize(QSize(300, 150)) self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.dc_signal.connect(self._data_changed, type=Qt.QueuedConnection) self.context_menu = None self.setContextMenuPolicy(Qt.DefaultContextMenu) if hasattr(self, 'setSubtitleFont'): self.setSubtitleFont(QFont(rating_font()))
def __init__(self, parent=None): pictureflow.PictureFlow.__init__( self, parent, config['cover_flow_queue_length'] + 1) self.setMinimumSize(QSize(300, 150)) self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.dc_signal.connect(self._data_changed, type=Qt.QueuedConnection) self.context_menu = None self.setContextMenuPolicy(Qt.DefaultContextMenu) self.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio']) self.setSubtitleFont(QFont(rating_font())) if not gprefs['cover_browser_reflections']: self.setShowReflections(False)
def __init__(self, parent=None, is_half_star=False): QComboBox.__init__(self, parent) self.addItem(_('Not rated')) if is_half_star: [self.addItem(stars(x, True)) for x in range(1, 11)] else: [self.addItem(stars(x)) for x in (2, 4, 6, 8, 10)] self.rating_font = QFont(rating_font()) self.undo_stack = QUndoStack(self) self.undo, self.redo = self.undo_stack.undo, self.undo_stack.redo self.allow_undo = False self.is_half_star = is_half_star self.delegate = RatingItemDelegate(self) self.view().setItemDelegate(self.delegate) self.view().setStyleSheet('QListView { background: palette(window) }\nQListView::item { padding: 6px }') self.setMaxVisibleItems(self.count()) self.currentIndexChanged.connect(self.update_font)
def __init__(self, parent=None): pictureflow.PictureFlow.__init__(self, parent, config['cover_flow_queue_length']+1) self.setMinimumSize(QSize(300, 150)) self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.dc_signal.connect(self._data_changed, type=Qt.QueuedConnection) self.context_menu = None self.setContextMenuPolicy(Qt.DefaultContextMenu) try: self.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio']) except AttributeError: pass # source checkout without updated binary if hasattr(self, 'setSubtitleFont'): self.setSubtitleFont(QFont(rating_font())) if not gprefs['cover_browser_reflections']: self.setShowReflections(False)
def show_details(self, index): f = rating_font() book = self.model().data(index, Qt.UserRole) parts = ["<center>", "<h2>%s</h2>" % book.title, "<div><i>%s</i></div>" % authors_to_string(book.authors)] if not book.is_null("series"): series = book.format_field("series") if series[1]: parts.append("<div>%s: %s</div>" % series) if not book.is_null("rating"): style = "style='font-family:\"%s\"'" % f parts.append("<div %s>%s</div>" % (style, "\u2605" * int(book.rating))) parts.append("</center>") if book.identifiers: urls = urls_from_identifiers(book.identifiers) ids = ['<a href="%s">%s</a>' % (url, name) for name, ign, ign, url in urls] if ids: parts.append("<div><b>%s:</b> %s</div><br>" % (_("See at"), ", ".join(ids))) if book.tags: parts.append("<div>%s</div><div>\u00a0</div>" % ", ".join(book.tags)) if book.comments: parts.append(comments_to_html(book.comments)) self.show_details_signal.emit("".join(parts))
def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args, **kwargs) self.old_look = gprefs['tag_browser_old_look'] self.rating_pat = re.compile(r'[%s]' % rating_to_stars(3, True)) self.rating_font = QFont(rating_font())
def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args, **kwargs) self.old_look = False self.rating_pat = re.compile(r'[%s]' % rating_to_stars(3, True)) self.rating_font = QFont(rating_font())
def __init__(self, parent=None, is_half_star=False): QAbstractListModel.__init__(self, parent) self.is_half_star = is_half_star self.rating_font = QFont(rating_font()) self.null_text = _('Not rated')
def __init__(self, parent=None, is_half_star=False): QAbstractListModel.__init__(self, parent) self.is_half_star = is_half_star self.rating_font = QFont(rating_font()) self.null_text = _("Not rated")
def render_data(mi, use_roman_numbers=True, all_fields=False): return mi_to_html( mi, use_roman_numbers=use_roman_numbers, rating_font=rating_font(), rtl=is_rtl(), default_author_link=default_author_link() )
def set_subtitle_font(self, for_ratings=True): if for_ratings: self.setSubtitleFont(QFont(rating_font())) else: self.setSubtitleFont(self.font())
def set_subtitle_font(self, for_ratings=True): if for_ratings: self.setSubtitleFont(QFont(rating_font())) else: self.setSubtitleFont(self.font())
def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args, **kwargs) self.old_look = False self.rating_pat = re.compile(r'[%s]' % rating_to_stars(3, True)) self.rating_font = QFont(rating_font()) self.completion_data = None
def render_data(mi, use_roman_numbers=True, all_fields=False): field_list = get_field_list(getattr(mi, 'field_metadata', field_metadata)) field_list = [(x, all_fields or display) for x, display in field_list] return mi_to_html(mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rtl=is_rtl(), rating_font=rating_font(), default_author_link=default_author_link())
def render_data(mi, use_roman_numbers=True, all_fields=False): ans = [] isdevice = not hasattr(mi, 'id') fm = getattr(mi, 'field_metadata', field_metadata) for field, display in get_field_list(fm): metadata = fm.get(field, None) if field == 'sort': field = 'title_sort' if all_fields: display = True if metadata['datatype'] == 'bool': isnull = mi.get(field) is None else: isnull = mi.is_null(field) if (not display or not metadata or isnull or field == 'comments'): continue name = metadata['name'] if not name: name = field name += ':' if metadata['datatype'] == 'comments': val = getattr(mi, field) if val: val = force_unicode(val) ans.append((field, u'<td class="comments" colspan="2">%s</td>'%comments_to_html(val))) elif metadata['datatype'] == 'rating': val = getattr(mi, field) if val: val = val/2.0 ans.append((field, u'<td class="title">%s</td><td class="rating" ' 'style=\'font-family:"%s"\'>%s</td>'%( name, rating_font(), u'\u2605'*int(val)))) elif metadata['datatype'] == 'composite' and \ metadata['display'].get('contains_html', False): val = getattr(mi, field) if val: val = force_unicode(val) ans.append((field, u'<td class="title">%s</td><td>%s</td>'% (name, comments_to_html(val)))) elif field == 'path': if mi.path: path = force_unicode(mi.path, filesystem_encoding) scheme = u'devpath' if isdevice else u'path' url = prepare_string_for_xml(path if isdevice else unicode(mi.id), True) pathstr = _('Click to open') extra = '' if isdevice: durl = url if durl.startswith('mtp:::'): durl = ':::'.join((durl.split(':::'))[2:]) extra = '<br><span style="font-size:smaller">%s</span>'%( prepare_string_for_xml(durl)) link = u'<a href="%s:%s" title="%s">%s</a>%s' % (scheme, url, prepare_string_for_xml(path, True), pathstr, extra) ans.append((field, u'<td class="title">%s</td><td>%s</td>'%(name, link))) elif field == 'formats': if isdevice: continue fmts = [u'<a href="format:%s:%s">%s</a>' % (mi.id, x, x) for x in mi.formats] ans.append((field, u'<td class="title">%s</td><td>%s</td>'%(name, u', '.join(fmts)))) elif field == 'identifiers': urls = urls_from_identifiers(mi.identifiers) links = [u'<a href="%s" title="%s:%s">%s</a>' % (url, id_typ, id_val, name) for name, id_typ, id_val, url in urls] links = u', '.join(links) if links: ans.append((field, u'<td class="title">%s</td><td>%s</td>'%( _('Ids')+':', links))) elif field == 'authors' and not isdevice: authors = [] formatter = EvalFormatter() for aut in mi.authors: link = '' if mi.author_link_map[aut]: link = mi.author_link_map[aut] elif gprefs.get('default_author_link'): vals = {'author': aut.replace(' ', '+')} try: vals['author_sort'] = mi.author_sort_map[aut].replace(' ', '+') except: vals['author_sort'] = aut.replace(' ', '+') link = formatter.safe_format( gprefs.get('default_author_link'), vals, '', vals) if link: link = prepare_string_for_xml(link) authors.append(u'<a calibre-data="authors" href="%s">%s</a>'%(link, aut)) else: authors.append(aut) ans.append((field, u'<td class="title">%s</td><td>%s</td>'%(name, u' & '.join(authors)))) elif field == 'languages': if not mi.languages: continue names = filter(None, map(calibre_langcode_to_name, mi.languages)) ans.append((field, u'<td class="title">%s</td><td>%s</td>'%(name, u', '.join(names)))) else: val = mi.format_field(field)[-1] if val is None: continue val = prepare_string_for_xml(val) if metadata['datatype'] == 'series': sidx = mi.get(field+'_index') if sidx is None: sidx = 1.0 val = _('Book %(sidx)s of <span class="series_name">%(series)s</span>')%dict( sidx=fmt_sidx(sidx, use_roman=use_roman_numbers), series=prepare_string_for_xml(getattr(mi, field))) elif metadata['datatype'] == 'datetime': aval = getattr(mi, field) if is_date_undefined(aval): continue ans.append((field, u'<td class="title">%s</td><td>%s</td>'%(name, val))) dc = getattr(mi, 'device_collections', []) if dc: dc = u', '.join(sorted(dc, key=sort_key)) ans.append(('device_collections', u'<td class="title">%s</td><td>%s</td>'%( _('Collections')+':', dc))) def classname(field): try: dt = fm[field]['datatype'] except: dt = 'text' return 'datatype_%s'%dt ans = [u'<tr id="%s" class="%s">%s</tr>'%(field.replace('#', '_'), classname(field), html) for field, html in ans] # print '\n'.join(ans) return u'<table class="fields">%s</table>'%(u'\n'.join(ans))
def render_data(mi, use_roman_numbers=True, all_fields=False): return mi_to_html(mi, use_roman_numbers=use_roman_numbers, rating_font=rating_font())
def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args, **kwargs) self.old_look = gprefs['tag_browser_old_look'] self.rating_pat = re.compile(r'[%s]' % rating_to_stars(3, True)) self.rating_font = QFont(rating_font())
def render_data(mi, use_roman_numbers=True, all_fields=False): ans = [] comment_fields = [] isdevice = not hasattr(mi, "id") fm = getattr(mi, "field_metadata", field_metadata) row = u'<td class="title">%s</td><td class="value">%s</td>' for field, display in get_field_list(fm): metadata = fm.get(field, None) if field == "sort": field = "title_sort" if all_fields: display = True if metadata["datatype"] == "bool": isnull = mi.get(field) is None else: isnull = mi.is_null(field) if not display or not metadata or isnull: continue name = metadata["name"] if not name: name = field name += ":" if metadata["datatype"] == "comments" or field == "comments": val = getattr(mi, field) if val: val = force_unicode(val) comment_fields.append(comments_to_html(val)) elif metadata["datatype"] == "rating": val = getattr(mi, field) if val: val = val / 2.0 ans.append( ( field, u'<td class="title">%s</td><td class="rating value" ' "style='font-family:\"%s\"'>%s</td>" % (name, rating_font(), u"\u2605" * int(val)), ) ) elif metadata["datatype"] == "composite" and metadata["display"].get("contains_html", False): val = getattr(mi, field) if val: val = force_unicode(val) ans.append((field, row % (name, comments_to_html(val)))) elif field == "path": if mi.path: path = force_unicode(mi.path, filesystem_encoding) scheme = u"devpath" if isdevice else u"path" url = prepare_string_for_xml(path if isdevice else unicode(mi.id), True) pathstr = _("Click to open") extra = "" if isdevice: durl = url if durl.startswith("mtp:::"): durl = ":::".join((durl.split(":::"))[2:]) extra = '<br><span style="font-size:smaller">%s</span>' % (prepare_string_for_xml(durl)) link = u'<a href="%s:%s" title="%s">%s</a>%s' % ( scheme, url, prepare_string_for_xml(path, True), pathstr, extra, ) ans.append((field, row % (name, link))) elif field == "formats": if isdevice: continue fmts = [u'<a href="format:%s:%s">%s</a>' % (mi.id, x, x) for x in mi.formats] ans.append((field, row % (name, u", ".join(fmts)))) elif field == "identifiers": urls = urls_from_identifiers(mi.identifiers) links = [ u'<a href="%s" title="%s:%s">%s</a>' % (url, id_typ, id_val, name) for name, id_typ, id_val, url in urls ] links = u", ".join(links) if links: ans.append((field, row % (_("Ids") + ":", links))) elif field == "authors" and not isdevice: authors = [] formatter = EvalFormatter() for aut in mi.authors: link = "" if mi.author_link_map[aut]: link = mi.author_link_map[aut] elif gprefs.get("default_author_link"): vals = {"author": aut.replace(" ", "+")} try: vals["author_sort"] = mi.author_sort_map[aut].replace(" ", "+") except: vals["author_sort"] = aut.replace(" ", "+") link = formatter.safe_format(gprefs.get("default_author_link"), vals, "", vals) if link: link = prepare_string_for_xml(link) authors.append(u'<a calibre-data="authors" href="%s">%s</a>' % (link, aut)) else: authors.append(aut) ans.append((field, row % (name, u" & ".join(authors)))) elif field == "languages": if not mi.languages: continue names = filter(None, map(calibre_langcode_to_name, mi.languages)) ans.append((field, row % (name, u", ".join(names)))) else: val = mi.format_field(field)[-1] if val is None: continue val = prepare_string_for_xml(val) if metadata["datatype"] == "series": sidx = mi.get(field + "_index") if sidx is None: sidx = 1.0 val = _('Book %(sidx)s of <span class="series_name">%(series)s</span>') % dict( sidx=fmt_sidx(sidx, use_roman=use_roman_numbers), series=prepare_string_for_xml(getattr(mi, field)) ) elif metadata["datatype"] == "datetime": aval = getattr(mi, field) if is_date_undefined(aval): continue ans.append((field, row % (name, val))) dc = getattr(mi, "device_collections", []) if dc: dc = u", ".join(sorted(dc, key=sort_key)) ans.append(("device_collections", row % (_("Collections") + ":", dc))) def classname(field): try: dt = fm[field]["datatype"] except: dt = "text" return "datatype_%s" % dt ans = [u'<tr id="%s" class="%s">%s</tr>' % (field.replace("#", "_"), classname(field), html) for field, html in ans] # print '\n'.join(ans) return u'<table class="fields">%s</table>' % (u"\n".join(ans)), comment_fields
def render_data(mi, use_roman_numbers=True, all_fields=False): ans = [] isdevice = not hasattr(mi, 'id') fm = getattr(mi, 'field_metadata', field_metadata) for field, display in get_field_list(fm): metadata = fm.get(field, None) if field == 'sort': field = 'title_sort' if all_fields: display = True if metadata['datatype'] == 'bool': isnull = mi.get(field) is None else: isnull = mi.is_null(field) if (not display or not metadata or isnull or field == 'comments'): continue name = metadata['name'] if not name: name = field name += ':' if metadata['datatype'] == 'comments': val = getattr(mi, field) if val: val = force_unicode(val) ans.append( (field, u'<td class="comments" colspan="2">%s</td>' % comments_to_html(val))) elif metadata['datatype'] == 'rating': val = getattr(mi, field) if val: val = val / 2.0 ans.append( (field, u'<td class="title">%s</td><td class="rating" ' 'style=\'font-family:"%s"\'>%s</td>' % (name, rating_font(), u'\u2605' * int(val)))) elif metadata['datatype'] == 'composite' and \ metadata['display'].get('contains_html', False): val = getattr(mi, field) if val: val = force_unicode(val) ans.append((field, u'<td class="title">%s</td><td>%s</td>' % (name, comments_to_html(val)))) elif field == 'path': if mi.path: path = force_unicode(mi.path, filesystem_encoding) scheme = u'devpath' if isdevice else u'path' url = prepare_string_for_xml( path if isdevice else unicode(mi.id), True) pathstr = _('Click to open') extra = '' if isdevice: durl = url if durl.startswith('mtp:::'): durl = ':::'.join((durl.split(':::'))[2:]) extra = '<br><span style="font-size:smaller">%s</span>' % ( prepare_string_for_xml(durl)) link = u'<a href="%s:%s" title="%s">%s</a>%s' % ( scheme, url, prepare_string_for_xml(path, True), pathstr, extra) ans.append( (field, u'<td class="title">%s</td><td>%s</td>' % (name, link))) elif field == 'formats': if isdevice: continue fmts = [ u'<a href="format:%s:%s">%s</a>' % (mi.id, x, x) for x in mi.formats ] ans.append((field, u'<td class="title">%s</td><td>%s</td>' % (name, u', '.join(fmts)))) elif field == 'identifiers': urls = urls_from_identifiers(mi.identifiers) links = [ u'<a href="%s" title="%s:%s">%s</a>' % (url, id_typ, id_val, name) for name, id_typ, id_val, url in urls ] links = u', '.join(links) if links: ans.append((field, u'<td class="title">%s</td><td>%s</td>' % (_('Ids') + ':', links))) elif field == 'authors' and not isdevice: authors = [] formatter = EvalFormatter() for aut in mi.authors: link = '' if mi.author_link_map[aut]: link = mi.author_link_map[aut] elif gprefs.get('default_author_link'): vals = {'author': aut.replace(' ', '+')} try: vals['author_sort'] = mi.author_sort_map[aut].replace( ' ', '+') except: vals['author_sort'] = aut.replace(' ', '+') link = formatter.safe_format( gprefs.get('default_author_link'), vals, '', vals) if link: link = prepare_string_for_xml(link) authors.append(u'<a href="%s">%s</a>' % (link, aut)) else: authors.append(aut) ans.append((field, u'<td class="title">%s</td><td>%s</td>' % (name, u' & '.join(authors)))) elif field == 'languages': if not mi.languages: continue names = filter(None, map(calibre_langcode_to_name, mi.languages)) ans.append((field, u'<td class="title">%s</td><td>%s</td>' % (name, u', '.join(names)))) else: val = mi.format_field(field)[-1] if val is None: continue val = prepare_string_for_xml(val) if metadata['datatype'] == 'series': sidx = mi.get(field + '_index') if sidx is None: sidx = 1.0 val = _( 'Book %(sidx)s of <span class="series_name">%(series)s</span>' ) % dict(sidx=fmt_sidx(sidx, use_roman=use_roman_numbers), series=prepare_string_for_xml(getattr(mi, field))) elif metadata['datatype'] == 'datetime': aval = getattr(mi, field) if is_date_undefined(aval): continue ans.append( (field, u'<td class="title">%s</td><td>%s</td>' % (name, val))) dc = getattr(mi, 'device_collections', []) if dc: dc = u', '.join(sorted(dc, key=sort_key)) ans.append( ('device_collections', u'<td class="title">%s</td><td>%s</td>' % (_('Collections') + ':', dc))) def classname(field): try: dt = fm[field]['datatype'] except: dt = 'text' return 'datatype_%s' % dt ans = [ u'<tr id="%s" class="%s">%s</tr>' % (field.replace('#', '_'), classname(field), html) for field, html in ans ] # print '\n'.join(ans) return u'<table class="fields">%s</table>' % (u'\n'.join(ans))