mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a dock for the inspector
This commit is contained in:
parent
c4295355a2
commit
fa23f3d43f
@ -24,15 +24,17 @@ class EbookViewer(MainWindow):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
MainWindow.__init__(self, None)
|
MainWindow.__init__(self, None)
|
||||||
self.book_prepared.connect(self.load_finished, type=Qt.QueuedConnection)
|
self.book_prepared.connect(self.load_finished, type=Qt.QueuedConnection)
|
||||||
self.web_view = WebView(self)
|
|
||||||
self.setCentralWidget(self.web_view)
|
|
||||||
|
|
||||||
def create_dock(title, name, areas=Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea):
|
def create_dock(title, name, areas=Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea):
|
||||||
ans = QDockWidget(title, self)
|
ans = QDockWidget(title, self)
|
||||||
ans.setObjectName(name)
|
ans.setObjectName(name)
|
||||||
ans.close()
|
ans.close()
|
||||||
|
return ans
|
||||||
|
|
||||||
self.toc_dock = create_dock(_('Table of Contents'), 'toc-dock')
|
self.toc_dock = create_dock(_('Table of Contents'), 'toc-dock')
|
||||||
|
self.inspector_dock = create_dock(_('Inspector'), 'inspector')
|
||||||
|
self.web_view = WebView(self)
|
||||||
|
self.setCentralWidget(self.web_view)
|
||||||
|
|
||||||
def handle_commandline_arg(self, arg):
|
def handle_commandline_arg(self, arg):
|
||||||
if arg and os.path.isfile(arg) and os.access(arg, os.R_OK):
|
if arg and os.path.isfile(arg) and os.access(arg, os.R_OK):
|
||||||
|
@ -6,10 +6,12 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from PyQt5.Qt import QApplication, QBuffer, QByteArray, QSize, QUrl
|
from PyQt5.Qt import (
|
||||||
|
QApplication, QBuffer, QByteArray, QHBoxLayout, QSize, QTimer, QUrl, QWidget
|
||||||
|
)
|
||||||
from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler
|
from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler
|
||||||
from PyQt5.QtWebEngineWidgets import (
|
from PyQt5.QtWebEngineWidgets import (
|
||||||
QWebEnginePage, QWebEngineProfile, QWebEngineScript
|
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineView
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre import as_unicode, prints
|
from calibre import as_unicode, prints
|
||||||
@ -179,6 +181,30 @@ def viewer_html():
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
class Inspector(QWidget):
|
||||||
|
|
||||||
|
def __init__(self, dock_action, parent=None):
|
||||||
|
QWidget.__init__(self, parent=parent)
|
||||||
|
self.view_to_debug = parent
|
||||||
|
self.view = None
|
||||||
|
self.layout = QHBoxLayout(self)
|
||||||
|
self.layout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
self.dock_action = dock_action
|
||||||
|
QTimer.singleShot(0, self.connect_to_dock)
|
||||||
|
|
||||||
|
def connect_to_dock(self):
|
||||||
|
ac = self.dock_action
|
||||||
|
ac.toggled.connect(self.visibility_changed)
|
||||||
|
if ac.isChecked():
|
||||||
|
self.visibility_changed(True)
|
||||||
|
|
||||||
|
def visibility_changed(self, visible):
|
||||||
|
if visible and self.view is None:
|
||||||
|
self.view = QWebEngineView(self.view_to_debug)
|
||||||
|
self.view_to_debug.page().setDevToolsPage(self.view.page())
|
||||||
|
self.layout.addWidget(self.view)
|
||||||
|
|
||||||
|
|
||||||
class WebView(RestartingWebEngineView):
|
class WebView(RestartingWebEngineView):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -194,6 +220,8 @@ class WebView(RestartingWebEngineView):
|
|||||||
self.setPage(self._page)
|
self.setPage(self._page)
|
||||||
self.setAcceptDrops(False)
|
self.setAcceptDrops(False)
|
||||||
self.clear()
|
self.clear()
|
||||||
|
if parent is not None:
|
||||||
|
self.inspector = Inspector(parent.toc_dock.toggleViewAction(), self)
|
||||||
|
|
||||||
def render_process_died(self):
|
def render_process_died(self):
|
||||||
if self.dead_renderer_error_shown:
|
if self.dead_renderer_error_shown:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user