mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Connect up the Qt bridge in the viewer
This commit is contained in:
parent
25ef13c6ee
commit
8b0cdbad13
@ -70,3 +70,4 @@ class EbookViewer(MainWindow):
|
||||
det_msg=data['tb'], show=True)
|
||||
return
|
||||
set_book_path(data['base'])
|
||||
self.web_view.start_book_load()
|
||||
|
@ -122,14 +122,9 @@ def create_profile():
|
||||
|
||||
class ViewerBridge(Bridge):
|
||||
|
||||
request_sync = from_js(object, object, object)
|
||||
request_split = from_js(object, object)
|
||||
live_css_data = from_js(object)
|
||||
|
||||
go_to_sourceline_address = to_js()
|
||||
go_to_anchor = to_js()
|
||||
set_split_mode = to_js()
|
||||
live_css = to_js()
|
||||
start_book_load = to_js()
|
||||
|
||||
|
||||
class WebPage(QWebEnginePage):
|
||||
@ -169,6 +164,8 @@ class WebView(RestartingWebEngineView):
|
||||
w = QApplication.instance().desktop().availableGeometry(self).width()
|
||||
self._size_hint = QSize(int(w/3), int(w/2))
|
||||
self._page = WebPage(self)
|
||||
self.bridge.bridge_ready.connect(self.on_bridge_ready)
|
||||
self.pending_bridge_ready_actions = set()
|
||||
self.setPage(self._page)
|
||||
self.setAcceptDrops(False)
|
||||
self.clear()
|
||||
@ -189,3 +186,17 @@ class WebView(RestartingWebEngineView):
|
||||
|
||||
def clear(self):
|
||||
self.setHtml('<p> ', QUrl('{}://{}/'.format(FAKE_PROTOCOL, FAKE_HOST)))
|
||||
|
||||
@property
|
||||
def bridge(self):
|
||||
return self._page.bridge
|
||||
|
||||
def on_bridge_ready(self):
|
||||
for func, args in self.pending_bridge_ready_actions:
|
||||
getattr(self.bridge, func)(*args)
|
||||
|
||||
def start_book_load(self):
|
||||
if self.bridge.ready:
|
||||
self.bridge.start_book_load()
|
||||
else:
|
||||
self.pending_bridge_ready_actions.add(('start_book_load', ()))
|
||||
|
@ -73,6 +73,8 @@ class to_js_bound(QObject):
|
||||
|
||||
class Bridge(QObject):
|
||||
|
||||
bridge_ready = pyqtSignal()
|
||||
|
||||
def __init__(self, page):
|
||||
QObject.__init__(self, page)
|
||||
self._signals = json.dumps(tuple({k for k, v in self.__class__.__dict__.iteritems() if isinstance(v, pyqtSignal)}))
|
||||
@ -100,6 +102,7 @@ class Bridge(QObject):
|
||||
if isinstance(v, to_js):
|
||||
setattr(self, k, to_js_bound(self, k))
|
||||
self.page.runJavaScript('python_comm._register_signals(' + self._signals + ')', QWebEngineScript.ApplicationWorld)
|
||||
self.bridge_ready.emit()
|
||||
|
||||
def _poll_for_messages(self):
|
||||
self.page.runJavaScript('python_comm._poll()', QWebEngineScript.ApplicationWorld, self._dispatch_messages)
|
||||
|
@ -5,6 +5,7 @@ from __python__ import bound_methods, hash_literals
|
||||
|
||||
from elementmaker import E
|
||||
from read_book.globals import runtime, ui_operations
|
||||
from qt import from_python
|
||||
|
||||
def container_div(id):
|
||||
return E.div(id=id, style='margin: 0; padding: 0; display: none')
|
||||
@ -28,13 +29,19 @@ def show_error(title, msg, details):
|
||||
pass # TODO: Implement this
|
||||
|
||||
|
||||
@from_python
|
||||
def start_book_load():
|
||||
print(111111111111111)
|
||||
|
||||
|
||||
if window is window.top:
|
||||
# main
|
||||
document.body.appendChild(E.iframe(srcdoc="<p> "))
|
||||
ui_operations.get_file = get_file
|
||||
ui_operations.get_mathjax_files = get_mathjax_files
|
||||
ui_operations.update_url_state = update_url_state
|
||||
ui_operations.show_error = show_error
|
||||
document.body.appendChild(E.div(id='loading'))
|
||||
document.body.appendChild(E.div(id='view'))
|
||||
else:
|
||||
# iframe
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user