def __init__(self, parent=None): QWidget.__init__(self, parent) self.l = l = QVBoxLayout(self) self.view = v = QWebEngineView(self) v.loadStarted.connect(self.load_started) v.loadProgress.connect(self.load_progress) v.loadFinished.connect(self.load_finished) l.addWidget(v) self.h = h = QHBoxLayout() l.addLayout(h) self.download_progress = d = DownloadProgress(self) h.addWidget(d) self.home_button = b = QPushButton(_('Home')) b.clicked.connect(self.home) h.addWidget(b) self.back_button = b = QPushButton(_('Back')) b.clicked.connect(v.back) h.addWidget(b) self.forward_button = b = QPushButton(_('Forward')) b.clicked.connect(v.forward) h.addWidget(b) self.progress_bar = b = QProgressBar(self) h.addWidget(b) self.reload_button = b = QPushButton(_('Reload')) b.clicked.connect(v.reload) h.addWidget(b)
def main(url): # This function is run in a separate process and can do anything it likes, # including use QWebEngine. Here it simply opens the passed in URL # in a QWebEngineView app = Application([]) w = QWebEngineView() w.setUrl(QUrl(url)) w.show() w.raise_() app.exec_()
def show_devtools(self): if not hasattr(self, '_devtools_page'): self._devtools_page = QWebEnginePage() self._devtools_view = QWebEngineView(self) self._devtools_view.setPage(self._devtools_page) self._page.setDevToolsPage(self._devtools_page) self._devtools_dialog = d = QDialog(self) d.setWindowTitle('Inspect Lookup page') v = QVBoxLayout(d) v.addWidget(self._devtools_view) d.bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) d.bb.rejected.connect(d.reject) v.addWidget(d.bb) d.resize(QSize(800, 600)) d.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose, False) self._devtools_dialog.show() self._page.triggerAction(QWebEnginePage.WebAction.InspectElement)
prints(self.webengine_crash_message) if self._last_reload_at is not None and monotonic() - self._last_reload_at < 2: self.render_process_failed.emit() prints('The Qt WebEngine Render process crashed too often') else: self._last_reload_at = monotonic() self.render_process_restarted.emit() prints('Restarting Qt WebEngine') if __name__ == '__main__': from calibre.gui2 import Application from calibre.gui2.tweak_book.preview import WebPage from qt.core import QMainWindow app = Application([]) view = QWebEngineView() page = WebPage(view) view.setPage(page) w = QMainWindow() w.setCentralWidget(view) class Test(Bridge): s1 = from_js(object) j1 = to_js() t = Test(view.page()) t.s1.connect(print) w.show() view.setHtml(''' <p>hello</p> ''') app.exec()
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)