mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Set viewer window title
This commit is contained in:
parent
7cfe60f705
commit
48a2990600
@ -48,6 +48,8 @@ class EbookViewer(MainWindow):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
MainWindow.__init__(self, None)
|
MainWindow.__init__(self, None)
|
||||||
|
self.base_window_title = _('E-book viewer')
|
||||||
|
self.setWindowTitle(self.base_window_title)
|
||||||
self.in_full_screen_mode = None
|
self.in_full_screen_mode = None
|
||||||
try:
|
try:
|
||||||
os.makedirs(annotations_dir)
|
os.makedirs(annotations_dir)
|
||||||
@ -161,6 +163,7 @@ class EbookViewer(MainWindow):
|
|||||||
|
|
||||||
def load_ebook(self, pathtoebook, open_at=None, reload_book=False):
|
def load_ebook(self, pathtoebook, open_at=None, reload_book=False):
|
||||||
# TODO: Implement open_at
|
# TODO: Implement open_at
|
||||||
|
self.setWindowTitle(_('Loading book … — {}').format(self.base_window_title))
|
||||||
self.web_view.show_preparing_message()
|
self.web_view.show_preparing_message()
|
||||||
self.save_annotations()
|
self.save_annotations()
|
||||||
self.current_book_data = {}
|
self.current_book_data = {}
|
||||||
@ -185,6 +188,7 @@ class EbookViewer(MainWindow):
|
|||||||
|
|
||||||
def load_finished(self, ok, data):
|
def load_finished(self, ok, data):
|
||||||
if not ok:
|
if not ok:
|
||||||
|
self.setWindowTitle(self.base_window_title)
|
||||||
error_dialog(self, _('Loading book failed'), _(
|
error_dialog(self, _('Loading book failed'), _(
|
||||||
'Failed to open the book at {0}. Click "Show details" for more info.').format(data['pathtoebook']),
|
'Failed to open the book at {0}. Click "Show details" for more info.').format(data['pathtoebook']),
|
||||||
det_msg=data['tb'], show=True)
|
det_msg=data['tb'], show=True)
|
||||||
@ -194,6 +198,7 @@ class EbookViewer(MainWindow):
|
|||||||
self.current_book_data['annotations_map'] = defaultdict(list)
|
self.current_book_data['annotations_map'] = defaultdict(list)
|
||||||
self.current_book_data['annotations_path_key'] = path_key(data['pathtoebook']) + '.json'
|
self.current_book_data['annotations_path_key'] = path_key(data['pathtoebook']) + '.json'
|
||||||
self.load_book_data()
|
self.load_book_data()
|
||||||
|
self.update_window_title()
|
||||||
self.web_view.start_book_load(initial_cfi=self.initial_cfi_for_current_book())
|
self.web_view.start_book_load(initial_cfi=self.initial_cfi_for_current_book())
|
||||||
|
|
||||||
def load_book_data(self):
|
def load_book_data(self):
|
||||||
@ -206,6 +211,8 @@ class EbookViewer(MainWindow):
|
|||||||
self.toc_model = TOC(toc)
|
self.toc_model = TOC(toc)
|
||||||
self.toc.setModel(self.toc_model)
|
self.toc.setModel(self.toc_model)
|
||||||
self.bookmarks_widget.set_bookmarks(self.current_book_data['annotations_map']['bookmark'])
|
self.bookmarks_widget.set_bookmarks(self.current_book_data['annotations_map']['bookmark'])
|
||||||
|
self.current_book_data['metadata'] = set_book_path.parsed_metadata
|
||||||
|
self.current_book_data['manifest'] = set_book_path.parsed_manifest
|
||||||
|
|
||||||
def load_book_annotations(self):
|
def load_book_annotations(self):
|
||||||
amap = self.current_book_data['annotations_map']
|
amap = self.current_book_data['annotations_map']
|
||||||
@ -219,6 +226,12 @@ class EbookViewer(MainWindow):
|
|||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
raw = f.read()
|
raw = f.read()
|
||||||
merge_annotations(parse_annotations(raw), amap)
|
merge_annotations(parse_annotations(raw), amap)
|
||||||
|
|
||||||
|
def update_window_title(self):
|
||||||
|
title = self.current_book_data['metadata']['title']
|
||||||
|
book_format = self.current_book_data['manifest']['book_format']
|
||||||
|
title = '{} [{}] — {}'.format(title, book_format, self.base_window_title)
|
||||||
|
self.setWindowTitle(title)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# CFI management {{{
|
# CFI management {{{
|
||||||
|
@ -29,6 +29,7 @@ from calibre.gui2.webengine import (
|
|||||||
)
|
)
|
||||||
from calibre.srv.code import get_translations_data
|
from calibre.srv.code import get_translations_data
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
|
from calibre.utils.serialize import json_loads
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -44,9 +45,14 @@ vprefs.defaults['main_window_geometry'] = None
|
|||||||
|
|
||||||
# Override network access to load data from the book {{{
|
# Override network access to load data from the book {{{
|
||||||
|
|
||||||
|
|
||||||
def set_book_path(path=None):
|
def set_book_path(path=None):
|
||||||
set_book_path.path = os.path.abspath(path)
|
if path is not None:
|
||||||
|
set_book_path.path = os.path.abspath(path)
|
||||||
|
set_book_path.metadata = get_data('calibre-book-metadata.json')[0]
|
||||||
|
set_book_path.manifest, set_book_path.manifest_mime = get_data('calibre-book-manifest.json')
|
||||||
|
set_book_path.metadata = get_data('calibre-book-metadata.json')[0]
|
||||||
|
set_book_path.parsed_metadata = json_loads(set_book_path.metadata)
|
||||||
|
set_book_path.parsed_manifest = json_loads(set_book_path.manifest)
|
||||||
|
|
||||||
|
|
||||||
def get_data(name):
|
def get_data(name):
|
||||||
@ -116,10 +122,8 @@ class UrlSchemeHandler(QWebEngineUrlSchemeHandler):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
rq.fail(rq.RequestFailed)
|
rq.fail(rq.RequestFailed)
|
||||||
elif name == 'manifest':
|
elif name == 'manifest':
|
||||||
manifest, mime_type = get_data('calibre-book-manifest.json')
|
data = b'[' + set_book_path.manifest + b',' + set_book_path.metadata + b']'
|
||||||
metadata = get_data('calibre-book-metadata.json')[0]
|
send_reply(rq, set_book_path.manifest_mime, data)
|
||||||
data = b'[' + manifest + b',' + metadata + b']'
|
|
||||||
send_reply(rq, mime_type, data)
|
|
||||||
elif name.startswith('mathjax/'):
|
elif name.startswith('mathjax/'):
|
||||||
from calibre.gui2.viewer.mathjax import monkeypatch_mathjax
|
from calibre.gui2.viewer.mathjax import monkeypatch_mathjax
|
||||||
if name == 'mathjax/manifest.json':
|
if name == 'mathjax/manifest.json':
|
||||||
|
@ -201,6 +201,7 @@ class Container(ContainerBase):
|
|||||||
self.book_render_data = data = {
|
self.book_render_data = data = {
|
||||||
'version': RENDER_VERSION,
|
'version': RENDER_VERSION,
|
||||||
'toc':toc,
|
'toc':toc,
|
||||||
|
'book_format': book_fmt,
|
||||||
'spine':spine,
|
'spine':spine,
|
||||||
'link_uid': uuid4(),
|
'link_uid': uuid4(),
|
||||||
'book_hash': book_hash,
|
'book_hash': book_hash,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user