From 67f64b5e6a670d8806693fce562b2f8db6a587f7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 10 Jun 2014 16:49:44 +0200 Subject: [PATCH] Support printing via javascript. --- qutebrowser/browser/webpage.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qutebrowser/browser/webpage.py b/qutebrowser/browser/webpage.py index 3a82646fd..014bd4b45 100644 --- a/qutebrowser/browser/webpage.py +++ b/qutebrowser/browser/webpage.py @@ -21,6 +21,7 @@ import sip from PyQt5.QtCore import QCoreApplication from PyQt5.QtNetwork import QNetworkReply from PyQt5.QtWidgets import QFileDialog +from PyQt5.QtPrintSupport import QPrintDialog from PyQt5.QtWebKitWidgets import QWebPage import qutebrowser.utils.message as message @@ -48,6 +49,7 @@ class BrowserPage(QWebPage): } self.setNetworkAccessManager( QCoreApplication.instance().networkmanager) + self.printRequested.connect(self.on_print_requested) def _handle_errorpage(self, opt, out): """Display an error page if needed. @@ -111,6 +113,11 @@ class BrowserPage(QWebPage): suggested_file) return True + def on_print_requested(self, frame): + """Handle printing when requested via javascript.""" + printdiag = QPrintDialog() + printdiag.open(lambda: frame.print(printdiag.printer())) + def userAgentForUrl(self, url): """Override QWebPage::userAgentForUrl to customize the user agent.""" ua = config.get('network', 'user-agent')