Make the current CFI available in python

This commit is contained in:
Kovid Goyal 2019-02-07 09:49:21 +05:30
parent 2c15434bab
commit 289c42b87f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 1 deletions

View File

@ -239,6 +239,7 @@ class WebView(RestartingWebEngineView):
def __init__(self, parent=None):
self._host_widget = None
self.current_cfi = None
RestartingWebEngineView.__init__(self, parent)
self.dead_renderer_error_shown = False
self.render_process_failed.connect(self.render_process_died)
@ -251,11 +252,20 @@ class WebView(RestartingWebEngineView):
self.setPage(self._page)
self.setAcceptDrops(False)
self.clear()
self.urlChanged.connect(self.url_changed)
if parent is not None:
self.inspector = Inspector(parent.inspector_dock.toggleViewAction(), self)
parent.inspector_dock.setWidget(self.inspector)
# QTimer.singleShot(300, lambda: (parent.inspector_dock.setVisible(True), parent.inspector_dock.setMinimumWidth(650)))
def url_changed(self, url):
if url.hasFragment():
frag = url.fragment(url.FullyDecoded)
if frag and frag.startswith('bookpos='):
cfi = frag[len('bookpos='):]
if cfi:
self.current_cfi = cfi
@property
def host_widget(self):
ans = self._host_widget

View File

@ -18,6 +18,7 @@ from read_book.globals import runtime, ui_operations
from read_book.iframe import main as iframe_main
from read_book.view import View
from session import session_defaults
from utils import encode_query_with_path
from viewer.constants import FAKE_HOST, FAKE_PROTOCOL
@ -113,7 +114,12 @@ def get_mathjax_files(proceed):
def update_url_state(replace):
pass # TODO: Implement this
if view and view.currently_showing:
bookpos = view.currently_showing.bookpos
if bookpos:
query = {'bookpos': bookpos}
query = encode_query_with_path(query)
window.history.pushState(None, '', query)
def show_error(title, msg, details):