mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use rating_to_stars in more places
This commit is contained in:
parent
dff20d07a5
commit
0dafccf479
@ -395,7 +395,7 @@ def check_doi(doi):
|
||||
return None
|
||||
|
||||
def rating_to_stars(value, allow_half_stars=False, star=u'★', half=u'½'):
|
||||
r = max(0, min(int(value), 10))
|
||||
r = max(0, min(int(value or 0), 10))
|
||||
if allow_half_stars:
|
||||
ans = u'★' * (r // 2)
|
||||
if r % 2:
|
||||
|
@ -11,7 +11,7 @@ from functools import partial
|
||||
from binascii import hexlify
|
||||
|
||||
from calibre import prepare_string_for_xml, force_unicode
|
||||
from calibre.ebooks.metadata import fmt_sidx
|
||||
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||
from calibre.ebooks.metadata.sources.identify import urls_from_identifiers
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.library.comments import comments_to_html, markdown
|
||||
@ -106,12 +106,7 @@ def mi_to_html(mi, field_list=None, default_author_link=None, use_roman_numbers=
|
||||
elif metadata['datatype'] == 'rating':
|
||||
val = getattr(mi, field)
|
||||
if val:
|
||||
if disp.get('allow_half_stars'):
|
||||
val = max(0, min(int(val), 10))
|
||||
star_string = u'\u2605' * (val // 2) + (u'\u00bd' if val % 2 else '')
|
||||
else:
|
||||
val = max(0, min(int(val/2.0), 5))
|
||||
star_string = u'\u2605' * val
|
||||
star_string = rating_to_stars(val, disp.get('allow_half_stars', False))
|
||||
ans.append((field,
|
||||
u'<td class="title">%s</td><td class="rating value" '
|
||||
'style=\'font-family:"%s"\'>%s</td>'%(
|
||||
|
@ -13,6 +13,7 @@ from PyQt5.Qt import (QImage, QSizePolicy, QTimer, QDialog, Qt, QSize, QAction,
|
||||
QStackedLayout, QLabel, QByteArray, pyqtSignal, QKeySequence, QFont)
|
||||
|
||||
from calibre import plugins
|
||||
from calibre.ebooks.metadata import rating_to_stars
|
||||
from calibre.constants import islinux
|
||||
from calibre.gui2 import (config, available_height, available_width, gprefs,
|
||||
rating_font)
|
||||
@ -125,7 +126,7 @@ if pictureflow is not None:
|
||||
def subtitle(self, index):
|
||||
if gprefs['show_rating_in_cover_browser']:
|
||||
try:
|
||||
return u'\u2605'*self.model.rating(index)
|
||||
return rating_to_stars(self.model.rating(index) * 2)
|
||||
except:
|
||||
pass
|
||||
return ''
|
||||
|
@ -23,7 +23,7 @@ from PyQt5.Qt import (
|
||||
|
||||
from calibre import fit_image, prints, prepare_string_for_xml, human_readable
|
||||
from calibre.constants import DEBUG, config_dir
|
||||
from calibre.ebooks.metadata import fmt_sidx
|
||||
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||
from calibre.utils import join_with_timeout
|
||||
from calibre.gui2 import gprefs, config
|
||||
from calibre.gui2.library.caches import CoverCache, ThumbnailCache
|
||||
@ -392,7 +392,7 @@ class CoverDelegate(QStyledItemDelegate):
|
||||
mi = db.get_proxy_metadata(book_id)
|
||||
display_name, ans, val, fm = mi.format_field_extended(field)
|
||||
if fm and fm['datatype'] == 'rating':
|
||||
ans = u'\u2605' * int(val/2.0) if val is not None else ''
|
||||
ans = rating_to_stars(val, fm['display'].get('allow_half_stars', False))
|
||||
return '' if ans is None else unicode(ans)
|
||||
except Exception:
|
||||
if DEBUG:
|
||||
|
@ -418,7 +418,7 @@ def test_glyph_ids():
|
||||
|
||||
def test_supports_text():
|
||||
data = P('fonts/calibreSymbols.otf', data=True)
|
||||
if not supports_text(data, '.\u2605★'):
|
||||
if not supports_text(data, '.★½'):
|
||||
raise RuntimeError('Incorrectly returning that text is not supported')
|
||||
if supports_text(data, 'abc'):
|
||||
raise RuntimeError('Incorrectly claiming that text is supported')
|
||||
|
Loading…
x
Reference in New Issue
Block a user