Merge branch 'issues/1630' of https://github.com/jdkaplan/qutebrowser into jdkaplan-issues/1630

This commit is contained in:
Florian Bruhin 2016-07-12 10:07:59 +02:00
commit 7a39021d41
5 changed files with 34 additions and 3 deletions

View File

@ -228,6 +228,7 @@ Contributors, sorted by the number of commits in descending order:
* Matthias Lisin * Matthias Lisin
* Marcel Schilling * Marcel Schilling
* Johannes Martinsson * Johannes Martinsson
* Jeremy Kaplan
* Jean-Christophe Petkovich * Jean-Christophe Petkovich
* Jay Kamat * Jay Kamat
* Helen Sherwood-Taylor * Helen Sherwood-Taylor

View File

@ -495,12 +495,13 @@ If the pasted text contains newlines, each line gets opened in its own tab.
[[print]] [[print]]
=== print === print
Syntax: +:print [*--preview*]+ Syntax: +:print [*--preview*] [*--pdf* 'file']+
Print the current/[count]th tab. Print the current/[count]th tab.
==== optional arguments ==== optional arguments
* +*-p*+, +*--preview*+: Show preview instead of printing. * +*-p*+, +*--preview*+: Show preview instead of printing.
* +*-f*+, +*--pdf*+: The file path to write the PDF to.
==== count ==== count
The tab index to print. The tab index to print.

View File

@ -28,7 +28,7 @@ import functools
from PyQt5.QtWidgets import QApplication, QTabBar from PyQt5.QtWidgets import QApplication, QTabBar
from PyQt5.QtCore import Qt, QUrl, QEvent from PyQt5.QtCore import Qt, QUrl, QEvent
from PyQt5.QtGui import QKeyEvent from PyQt5.QtGui import QKeyEvent
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog from PyQt5.QtPrintSupport import QPrintDialog, QPrinter, QPrintPreviewDialog
from PyQt5.QtWebKitWidgets import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
try: try:
from PyQt5.QtWebEngineWidgets import QWebEnginePage from PyQt5.QtWebEngineWidgets import QWebEnginePage
@ -299,12 +299,14 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', name='print', @cmdutils.register(instance='command-dispatcher', name='print',
scope='window') scope='window')
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def printpage(self, preview=False, count=None): @cmdutils.argument('pdf', flag='f', metavar='file')
def printpage(self, preview=False, count=None, *, pdf=None):
"""Print the current/[count]th tab. """Print the current/[count]th tab.
Args: Args:
preview: Show preview instead of printing. preview: Show preview instead of printing.
count: The tab index to print, or None. count: The tab index to print, or None.
pdf: The file path to write the PDF to.
""" """
if not qtutils.check_print_compat(): if not qtutils.check_print_compat():
# WORKAROUND (remove this when we bump the requirements to 5.3.0) # WORKAROUND (remove this when we bump the requirements to 5.3.0)
@ -320,6 +322,15 @@ class CommandDispatcher:
Qt.WindowMinimizeButtonHint) Qt.WindowMinimizeButtonHint)
diag.paintRequested.connect(tab.print) diag.paintRequested.connect(tab.print)
diag.exec_() diag.exec_()
elif pdf:
pdf = os.path.expanduser(pdf)
directory = os.path.dirname(pdf)
if directory and not os.path.exists(directory):
os.mkdir(directory)
printer = QPrinter()
printer.setOutputFileName(pdf)
tab.print(printer)
log.misc.debug("Print to file: {}".format(pdf))
else: else:
diag = QPrintDialog() diag = QPrintDialog()
diag.setAttribute(Qt.WA_DeleteOnClose) diag.setAttribute(Qt.WA_DeleteOnClose)

View File

@ -339,6 +339,13 @@ Feature: Various utility commands.
And I run :debug-pyeval QApplication.instance().activeModalWidget().close() And I run :debug-pyeval QApplication.instance().activeModalWidget().close()
Then no crash should happen Then no crash should happen
Scenario: print pdf
Given a new tmpdir
When I open data/hello.txt
And I run :print --pdf (tmpdir)/hello.pdf
And I wait for "Print to file: *" in the log or skip the test
Then the file hello.pdf should exist in the tmpdir
# :pyeval # :pyeval
Scenario: Running :pyeval Scenario: Running :pyeval

View File

@ -73,3 +73,14 @@ def check_cookie(quteproc, name, value):
data = json.loads(content) data = json.loads(content)
print(data) print(data)
assert data['cookies'][name] == value assert data['cookies'][name] == value
@bdd.given(bdd.parsers.parse('a new tmpdir'))
def tmpdir(tmpdir_factory):
return tmpdir_factory.mktemp('tmpdir')
@bdd.then(bdd.parsers.parse('the file {filename} should exist in the tmpdir'))
def file_exists(quteproc, tmpdir, filename):
path = tmpdir / filename
assert os.path.exists(str(path))