mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Viewer: Allow showing the "position in book" as was displayed in the top left of the viewer in calibre 3 in the header and footer. Fixes #1846700 [Absolute position for book viewer](https://bugs.launchpad.net/calibre/+bug/1846700)
This commit is contained in:
parent
cc54251368
commit
8ef6938e03
@ -37,6 +37,8 @@ def create_item(region, label):
|
|||||||
opt(_('Time to read book'), 'time-book'),
|
opt(_('Time to read book'), 'time-book'),
|
||||||
opt(_('Time to read chapter'), 'time-chapter'),
|
opt(_('Time to read chapter'), 'time-chapter'),
|
||||||
opt(_('Time to read chapter and book'), 'time-chapter-book'),
|
opt(_('Time to read chapter and book'), 'time-chapter-book'),
|
||||||
|
opt(_('Position in book'), 'pos-book'),
|
||||||
|
opt(_('Position in chapter'), 'pos-chapter'),
|
||||||
opt(_('Clock'), 'clock'),
|
opt(_('Clock'), 'clock'),
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
@ -125,7 +127,13 @@ def format_time_left(seconds):
|
|||||||
return _('{} h {} mins').format(hours, minutes)
|
return _('{} h {} mins').format(hours, minutes)
|
||||||
|
|
||||||
|
|
||||||
def render_head_foot(div, which, region, progress_frac, metadata, current_toc_node, current_toc_toplevel_node, book_time, chapter_time):
|
def format_pos(progress_frac, length):
|
||||||
|
pages = Math.ceil(length / 1000)
|
||||||
|
pos = progress_frac * pages
|
||||||
|
return f'{pos:.1f} / {pages}'
|
||||||
|
|
||||||
|
|
||||||
|
def render_head_foot(div, which, region, progress_frac, metadata, current_toc_node, current_toc_toplevel_node, book_time, chapter_time, pos):
|
||||||
template = get_session_data().get(which) or {}
|
template = get_session_data().get(which) or {}
|
||||||
field = template[region] or 'empty'
|
field = template[region] or 'empty'
|
||||||
interface_data = get_interface_data()
|
interface_data = get_interface_data()
|
||||||
@ -161,6 +169,11 @@ def render_head_foot(div, which, region, progress_frac, metadata, current_toc_no
|
|||||||
text = format_time_left(chapter_time)
|
text = format_time_left(chapter_time)
|
||||||
else:
|
else:
|
||||||
text = '{} ({})'.format(format_time_left(chapter_time), format_time_left(book_time))
|
text = '{} ({})'.format(format_time_left(chapter_time), format_time_left(book_time))
|
||||||
|
elif field.startswith('pos-'):
|
||||||
|
if field is 'pos-book':
|
||||||
|
text = format_pos(pos.current_progress_frac, pos.book_length)
|
||||||
|
else:
|
||||||
|
text = format_pos(pos.current_file_progress_frac, pos.chapter_length)
|
||||||
if not text:
|
if not text:
|
||||||
text = '\xa0'
|
text = '\xa0'
|
||||||
if text is not div.textContent:
|
if text is not div.textContent:
|
||||||
|
@ -726,6 +726,7 @@ class View:
|
|||||||
chapter_length = self.book.manifest.files[name]?.length or 0
|
chapter_length = self.book.manifest.files[name]?.length or 0
|
||||||
else:
|
else:
|
||||||
book_length = chapter_length = 0
|
book_length = chapter_length = 0
|
||||||
|
pos = {'current_progress_frac': self.current_progress_frac, 'book_length': book_length, 'chapter_length': chapter_length, 'current_file_progress_frac': self.current_file_progress_frac}
|
||||||
book_length *= max(0, 1 - self.current_progress_frac)
|
book_length *= max(0, 1 - self.current_progress_frac)
|
||||||
chapter_length *= max(0, 1 - self.current_file_progress_frac)
|
chapter_length *= max(0, 1 - self.current_file_progress_frac)
|
||||||
book_time = self.timers.time_for(book_length)
|
book_time = self.timers.time_for(book_length)
|
||||||
@ -735,9 +736,9 @@ class View:
|
|||||||
nonlocal has_clock
|
nonlocal has_clock
|
||||||
if sd.get(sz_attr, 20) > 5:
|
if sd.get(sz_attr, 20) > 5:
|
||||||
mi = self.book.metadata
|
mi = self.book.metadata
|
||||||
texta, hca = render_head_foot(div.firstChild, name, 'left', self.current_progress_frac, mi, self.current_toc_node, self.current_toc_toplevel_node, book_time, chapter_time)
|
texta, hca = render_head_foot(div.firstChild, name, 'left', self.current_progress_frac, mi, self.current_toc_node, self.current_toc_toplevel_node, book_time, chapter_time, pos)
|
||||||
textb, hcb = render_head_foot(div.firstChild.nextSibling, name, 'middle', self.current_progress_frac, mi, self.current_toc_node, self.current_toc_toplevel_node, book_time, chapter_time)
|
textb, hcb = render_head_foot(div.firstChild.nextSibling, name, 'middle', self.current_progress_frac, mi, self.current_toc_node, self.current_toc_toplevel_node, book_time, chapter_time, pos)
|
||||||
textc, hcc = render_head_foot(div.lastChild, name, 'right', self.current_progress_frac, mi, self.current_toc_node, self.current_toc_toplevel_node, book_time, chapter_time)
|
textc, hcc = render_head_foot(div.lastChild, name, 'right', self.current_progress_frac, mi, self.current_toc_node, self.current_toc_toplevel_node, book_time, chapter_time, pos)
|
||||||
has_clock = hca or hcb or hcc
|
has_clock = hca or hcb or hcc
|
||||||
if textc and not textb and not texta:
|
if textc and not textb and not texta:
|
||||||
# Want right-aligned
|
# Want right-aligned
|
||||||
|
Loading…
x
Reference in New Issue
Block a user