mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Track the current content file
This commit is contained in:
parent
5c8093e554
commit
90eb2c43f0
@ -33,6 +33,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 calibre.utils.serialize import json_loads
|
||||||
|
from calibre.utils.shared_file import share_open
|
||||||
from polyglot.builtins import as_bytes, iteritems
|
from polyglot.builtins import as_bytes, iteritems
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -75,7 +76,7 @@ def get_data(name):
|
|||||||
if path is None:
|
if path is None:
|
||||||
return None, None
|
return None, None
|
||||||
try:
|
try:
|
||||||
with lopen(path, 'rb') as f:
|
with share_open(path, 'rb') as f:
|
||||||
return f.read(), guess_type(name)
|
return f.read(), guess_type(name)
|
||||||
except EnvironmentError as err:
|
except EnvironmentError as err:
|
||||||
prints('Failed to read from book file: {} with error: {}'.format(name, as_unicode(err)))
|
prints('Failed to read from book file: {} with error: {}'.format(name, as_unicode(err)))
|
||||||
@ -235,6 +236,7 @@ def create_profile():
|
|||||||
class ViewerBridge(Bridge):
|
class ViewerBridge(Bridge):
|
||||||
|
|
||||||
view_created = from_js(object)
|
view_created = from_js(object)
|
||||||
|
content_file_changed = from_js(object)
|
||||||
set_session_data = from_js(object, object)
|
set_session_data = from_js(object, object)
|
||||||
set_local_storage = from_js(object, object)
|
set_local_storage = from_js(object, object)
|
||||||
reload_book = from_js()
|
reload_book = from_js()
|
||||||
@ -437,7 +439,7 @@ class WebView(RestartingWebEngineView):
|
|||||||
self._host_widget = None
|
self._host_widget = None
|
||||||
self.callback_id_counter = count()
|
self.callback_id_counter = count()
|
||||||
self.callback_map = {}
|
self.callback_map = {}
|
||||||
self.current_cfi = None
|
self.current_cfi = self.current_content_file = None
|
||||||
RestartingWebEngineView.__init__(self, parent)
|
RestartingWebEngineView.__init__(self, parent)
|
||||||
self.dead_renderer_error_shown = False
|
self.dead_renderer_error_shown = False
|
||||||
self.render_process_failed.connect(self.render_process_died)
|
self.render_process_failed.connect(self.render_process_died)
|
||||||
@ -448,6 +450,7 @@ class WebView(RestartingWebEngineView):
|
|||||||
self._page = WebPage(self)
|
self._page = WebPage(self)
|
||||||
self.bridge.bridge_ready.connect(self.on_bridge_ready)
|
self.bridge.bridge_ready.connect(self.on_bridge_ready)
|
||||||
self.bridge.view_created.connect(self.on_view_created)
|
self.bridge.view_created.connect(self.on_view_created)
|
||||||
|
self.bridge.content_file_changed.connect(self.on_content_file_created)
|
||||||
self.bridge.set_session_data.connect(self.set_session_data)
|
self.bridge.set_session_data.connect(self.set_session_data)
|
||||||
self.bridge.set_local_storage.connect(self.set_local_storage)
|
self.bridge.set_local_storage.connect(self.set_local_storage)
|
||||||
self.bridge.reload_book.connect(self.reload_book)
|
self.bridge.reload_book.connect(self.reload_book)
|
||||||
@ -556,6 +559,9 @@ class WebView(RestartingWebEngineView):
|
|||||||
def on_view_created(self, data):
|
def on_view_created(self, data):
|
||||||
self.view_created.emit(data)
|
self.view_created.emit(data)
|
||||||
|
|
||||||
|
def on_content_file_created(self, data):
|
||||||
|
self.current_content_file = data
|
||||||
|
|
||||||
def start_book_load(self, initial_position=None):
|
def start_book_load(self, initial_position=None):
|
||||||
key = (set_book_path.path,)
|
key = (set_book_path.path,)
|
||||||
self.execute_when_ready('start_book_load', key, initial_position, set_book_path.pathtoebook)
|
self.execute_when_ready('start_book_load', key, initial_position, set_book_path.pathtoebook)
|
||||||
|
@ -1035,6 +1035,8 @@ class View:
|
|||||||
self.book_load_started = False
|
self.book_load_started = False
|
||||||
if ui_operations.clear_history:
|
if ui_operations.clear_history:
|
||||||
ui_operations.clear_history()
|
ui_operations.clear_history()
|
||||||
|
if ui_operations.content_file_changed:
|
||||||
|
ui_operations.content_file_changed(self.currently_showing.name)
|
||||||
|
|
||||||
def set_progress_frac(self, progress_frac, file_progress_frac):
|
def set_progress_frac(self, progress_frac, file_progress_frac):
|
||||||
self.current_progress_frac = progress_frac or 0
|
self.current_progress_frac = progress_frac or 0
|
||||||
|
@ -337,6 +337,8 @@ if window is window.top:
|
|||||||
to_python.toggle_bookmarks()
|
to_python.toggle_bookmarks()
|
||||||
ui_operations.toggle_inspector = def():
|
ui_operations.toggle_inspector = def():
|
||||||
to_python.toggle_inspector()
|
to_python.toggle_inspector()
|
||||||
|
ui_operations.content_file_changed = def(name):
|
||||||
|
to_python.content_file_changed(name)
|
||||||
ui_operations.reset_interface = def():
|
ui_operations.reset_interface = def():
|
||||||
sd = get_session_data()
|
sd = get_session_data()
|
||||||
defaults = session_defaults()
|
defaults = session_defaults()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user