Add a check whether print works.

This commit is contained in:
Florian Bruhin 2014-06-16 10:21:03 +02:00
parent 43490202ca
commit 903de515e7
4 changed files with 18 additions and 9 deletions

4
BUGS
View File

@ -78,10 +78,6 @@ Upstream Bugs
Asked on SO: http://stackoverflow.com/q/23499159/2085149 Asked on SO: http://stackoverflow.com/q/23499159/2085149
TODO: report Qt bug TODO: report Qt bug
- Printing under windows produced blank pages
https://bugreports.qt-project.org/browse/QTBUG-19571
If this isn't fixed in Qt 5.3, bug should be reopened.
- QWebElement needs geometries() - QWebElement needs geometries()
https://bugreports.qt-project.org/browse/QTBUG-38698 https://bugreports.qt-project.org/browse/QTBUG-38698

View File

@ -35,7 +35,8 @@ import qutebrowser.utils.message as message
import qutebrowser.utils.webelem as webelem import qutebrowser.utils.webelem as webelem
import qutebrowser.browser.quickmarks as quickmarks import qutebrowser.browser.quickmarks as quickmarks
import qutebrowser.utils.log as log import qutebrowser.utils.log as log
from qutebrowser.utils.misc import check_overflow, shell_escape from qutebrowser.utils.misc import (check_overflow, shell_escape,
check_print_compat)
from qutebrowser.utils.editor import ExternalEditor from qutebrowser.utils.editor import ExternalEditor
from qutebrowser.commands.exceptions import CommandError from qutebrowser.commands.exceptions import CommandError
from qutebrowser.commands.userscripts import UserscriptRunner from qutebrowser.commands.userscripts import UserscriptRunner
@ -197,6 +198,9 @@ class CommandDispatcher:
Args: Args:
count: The tab index to print, or None. count: The tab index to print, or None.
""" """
if not check_print_compat():
raise CommandError("Printing on Qt < 5.3.0 on Windows is broken, "
"please upgrade!")
tab = self._tabs.cntwidget(count) tab = self._tabs.cntwidget(count)
if tab is not None: if tab is not None:
preview = QPrintPreviewDialog() preview = QPrintPreviewDialog()
@ -210,9 +214,9 @@ class CommandDispatcher:
Args: Args:
count: The tab index to print, or None. count: The tab index to print, or None.
""" """
# QTBUG: We only get blank pages. if not check_print_compat():
# https://bugreports.qt-project.org/browse/QTBUG-19571 raise CommandError("Printing on Qt < 5.3.0 on Windows is broken, "
# If this isn't fixed in Qt 5.3, bug should be reopened. "please upgrade!")
tab = self._tabs.cntwidget(count) tab = self._tabs.cntwidget(count)
if tab is not None: if tab is not None:
printdiag = QPrintDialog() printdiag = QPrintDialog()

View File

@ -30,7 +30,7 @@ import qutebrowser.utils.message as message
import qutebrowser.utils.url as urlutils import qutebrowser.utils.url as urlutils
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.utils.log as log import qutebrowser.utils.log as log
from qutebrowser.utils.misc import read_file from qutebrowser.utils.misc import read_file, check_print_compat
from qutebrowser.utils.usertypes import PromptMode from qutebrowser.utils.usertypes import PromptMode
@ -145,6 +145,10 @@ class BrowserPage(QWebPage):
def on_print_requested(self, frame): def on_print_requested(self, frame):
"""Handle printing when requested via javascript.""" """Handle printing when requested via javascript."""
if not check_print_compat():
message.error("Printing on Qt < 5.3.0 on Windows is broken, "
"please upgrade!")
return
printdiag = QPrintDialog() printdiag = QPrintDialog()
printdiag.open(lambda: frame.print(printdiag.printer())) printdiag.open(lambda: frame.print(printdiag.printer()))

View File

@ -397,6 +397,11 @@ def format_size(size, base=1024, suffix=''):
return '{:.02f}{}{}'.format(size, prefixes[-1], suffix) return '{:.02f}{}{}'.format(size, prefixes[-1], suffix)
def check_print_compat():
"""Check if printing should work in the given Qt version."""
return not (os.name == 'nt' and qt_version_check('5.3.0', operator.lt))
class EventLoop(QEventLoop): class EventLoop(QEventLoop):
"""A thin wrapper around QEventLoop. """A thin wrapper around QEventLoop.