mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
a38defca58
commit
67fcb5345d
@ -168,6 +168,7 @@ class ViewerBridge(Bridge):
|
|||||||
|
|
||||||
set_session_data = from_js(object, object)
|
set_session_data = from_js(object, object)
|
||||||
|
|
||||||
|
create_view = to_js()
|
||||||
start_book_load = to_js()
|
start_book_load = to_js()
|
||||||
|
|
||||||
|
|
||||||
@ -308,15 +309,16 @@ class WebView(RestartingWebEngineView):
|
|||||||
return self._page.bridge
|
return self._page.bridge
|
||||||
|
|
||||||
def on_bridge_ready(self):
|
def on_bridge_ready(self):
|
||||||
|
self.bridge.create_view(vprefs['session_data'])
|
||||||
for func, args in iteritems(self.pending_bridge_ready_actions):
|
for func, args in iteritems(self.pending_bridge_ready_actions):
|
||||||
getattr(self.bridge, func)(*args)
|
getattr(self.bridge, func)(*args)
|
||||||
|
|
||||||
def start_book_load(self, initial_cfi=None):
|
def start_book_load(self, initial_cfi=None):
|
||||||
key = (set_book_path.path,)
|
key = (set_book_path.path,)
|
||||||
if self.bridge.ready:
|
if self.bridge.ready:
|
||||||
self.bridge.start_book_load(key, vprefs['session_data'], initial_cfi)
|
self.bridge.start_book_load(key, initial_cfi)
|
||||||
else:
|
else:
|
||||||
self.pending_bridge_ready_actions['start_book_load'] = key, vprefs['session_data'], initial_cfi
|
self.pending_bridge_ready_actions['start_book_load'] = key, initial_cfi
|
||||||
|
|
||||||
def set_session_data(self, key, val):
|
def set_session_data(self, key, val):
|
||||||
if key == '*' and val is None:
|
if key == '*' and val is None:
|
||||||
|
@ -344,10 +344,13 @@ class View:
|
|||||||
if sd.get('max_text_width') or sd.get('max_text_height'):
|
if sd.get('max_text_width') or sd.get('max_text_height'):
|
||||||
self.set_margins()
|
self.set_margins()
|
||||||
|
|
||||||
|
def show_loading_message(self, msg):
|
||||||
|
self.overlay.show_loading_message(msg)
|
||||||
|
|
||||||
def show_loading(self):
|
def show_loading(self):
|
||||||
title = self.book.metadata.title
|
title = self.book.metadata.title
|
||||||
name = self.currently_showing.name
|
name = self.currently_showing.name
|
||||||
self.overlay.show_loading_message(_(
|
self.show_loading_message(_(
|
||||||
'Loading <i>{name}</i> from <i>{title}</i>, please wait...').format(name=name, title=title))
|
'Loading <i>{name}</i> from <i>{title}</i>, please wait...').format(name=name, title=title))
|
||||||
|
|
||||||
def hide_loading(self):
|
def hide_loading(self):
|
||||||
|
@ -22,9 +22,6 @@ from utils import encode_query_with_path
|
|||||||
from viewer.constants import FAKE_HOST, FAKE_PROTOCOL
|
from viewer.constants import FAKE_HOST, FAKE_PROTOCOL
|
||||||
|
|
||||||
|
|
||||||
def container_div(id):
|
|
||||||
return E.div(id=id, style='margin: 0; padding: 0; display: none')
|
|
||||||
|
|
||||||
runtime.is_standalone_viewer = True
|
runtime.is_standalone_viewer = True
|
||||||
runtime.FAKE_HOST = FAKE_HOST
|
runtime.FAKE_HOST = FAKE_HOST
|
||||||
runtime.FAKE_PROTOCOL = FAKE_PROTOCOL
|
runtime.FAKE_PROTOCOL = FAKE_PROTOCOL
|
||||||
@ -177,11 +174,14 @@ def create_session_data(prefs):
|
|||||||
|
|
||||||
|
|
||||||
@from_python
|
@from_python
|
||||||
def start_book_load(key, prefs, initial_cfi):
|
def create_view(prefs):
|
||||||
nonlocal view
|
nonlocal view
|
||||||
if view is None:
|
if view is None:
|
||||||
create_session_data(prefs)
|
create_session_data(prefs)
|
||||||
view = View(document.getElementById('view'))
|
view = View(document.getElementById('view'))
|
||||||
|
|
||||||
|
@from_python
|
||||||
|
def start_book_load(key, initial_cfi):
|
||||||
xhr = ajax('manifest', manifest_received.bind(None, key, initial_cfi), ok_code=0)
|
xhr = ajax('manifest', manifest_received.bind(None, key, initial_cfi), ok_code=0)
|
||||||
xhr.responseType = 'json'
|
xhr.responseType = 'json'
|
||||||
xhr.send()
|
xhr.send()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user