Support printing via javascript.

This commit is contained in:
Florian Bruhin 2014-06-10 16:49:44 +02:00
parent 57024f3174
commit 67f64b5e6a

View File

@ -21,6 +21,7 @@ import sip
from PyQt5.QtCore import QCoreApplication from PyQt5.QtCore import QCoreApplication
from PyQt5.QtNetwork import QNetworkReply from PyQt5.QtNetwork import QNetworkReply
from PyQt5.QtWidgets import QFileDialog from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtPrintSupport import QPrintDialog
from PyQt5.QtWebKitWidgets import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
import qutebrowser.utils.message as message import qutebrowser.utils.message as message
@ -48,6 +49,7 @@ class BrowserPage(QWebPage):
} }
self.setNetworkAccessManager( self.setNetworkAccessManager(
QCoreApplication.instance().networkmanager) QCoreApplication.instance().networkmanager)
self.printRequested.connect(self.on_print_requested)
def _handle_errorpage(self, opt, out): def _handle_errorpage(self, opt, out):
"""Display an error page if needed. """Display an error page if needed.
@ -111,6 +113,11 @@ class BrowserPage(QWebPage):
suggested_file) suggested_file)
return True 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): def userAgentForUrl(self, url):
"""Override QWebPage::userAgentForUrl to customize the user agent.""" """Override QWebPage::userAgentForUrl to customize the user agent."""
ua = config.get('network', 'user-agent') ua = config.get('network', 'user-agent')