mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make the current CFI available in python
This commit is contained in:
parent
2c15434bab
commit
289c42b87f
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user