本文整理汇总了Python中PyQt4.QtGui.QPrintDialog.setOption方法的典型用法代码示例。如果您正苦于以下问题:Python QPrintDialog.setOption方法的具体用法?Python QPrintDialog.setOption怎么用?Python QPrintDialog.setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QPrintDialog
的用法示例。
在下文中一共展示了QPrintDialog.setOption方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_
# 需要导入模块: from PyQt4.QtGui import QPrintDialog [as 别名]
# 或者: from PyQt4.QtGui.QPrintDialog import setOption [as 别名]
def print_(doc, filename=None, widget=None):
"""Prints the popplerqt4.Poppler.Document.
The filename is used in the dialog and print job name.
If the filename is not given, it defaults to a translation of "PDF Document".
The widget is a widget to use as parent for the print dialog etc.
"""
# Decide how we will print.
# on Windows and Mac OS X a print command must be specified, otherwise
# we'll use raster printing
s = QSettings()
s.beginGroup("helper_applications")
cmd = s.value("printcommand", "", type(""))
use_dialog = s.value("printcommand/dialog", False, bool)
resolution = s.value("printcommand/dpi", 300, int)
linux_lpr = False
if os.name != 'nt' and not sys.platform.startswith('darwin'):
# we're probably on Linux
if not cmd:
cmd = fileprinter.lprCommand()
if cmd:
linux_lpr = True
elif cmd.split('/')[-1] in fileprinter.lpr_commands:
linux_lpr = True
print_file = filename
title = os.path.basename(filename) if filename else _("PDF Document")
printer = QPrinter()
printer.setDocName(title)
printer.setPrintRange(QPrinter.AllPages)
if linux_lpr or use_dialog or not cmd:
dlg = QPrintDialog(printer, widget)
dlg.setMinMax(1, doc.numPages())
dlg.setOption(QPrintDialog.PrintToFile, False)
dlg.setWindowTitle(app.caption(_("Print {filename}").format(filename=title)))
result = dlg.exec_()
if widget:
dlg.deleteLater() # because it has a parent
if not result:
return # cancelled
if linux_lpr or '$ps' in cmd:
# make a PostScript file with the desired paper size
ps = QTemporaryFile()
if ps.open() and qpopplerview.printer.psfile(doc, printer, ps):
ps.close()
print_file = ps.fileName()
elif cmd:
if printer.printRange() != QPrinter.AllPages:
cmd = None # we can't cut out pages from a PDF file
elif '$pdf' not in cmd:
cmd += ' $pdf'
command = []
if linux_lpr:
# let all converted pages print
printer.setPrintRange(QPrinter.AllPages)
command = fileprinter.printCommand(cmd, printer, ps.fileName())
elif cmd and print_file:
for arg in helpers.shell_split(cmd):
if arg in ('$ps', '$pdf'):
command.append(print_file)
else:
arg = arg.replace('$printer', printer.printerName())
command.append(arg)
if command:
if subprocess.call(command):
QMessageBox.warning(widget, _("Printing Error"),
_("Could not send the document to the printer."))
return
else:
# Fall back printing of rendered raster images.
# It is unsure if the Poppler ArthurBackend ever will be ready for
# good rendering directly to a painter, so we'll fall back to using
# raster images.
p = Printer()
p.setDocument(doc)
p.setPrinter(printer)
p.setResolution(resolution)
d = QProgressDialog()
d.setModal(True)
d.setMinimumDuration(0)
d.setRange(0, len(p.pageList()) + 1)
d.canceled.connect(p.abort)
def progress(num, total, page):
d.setValue(num)
d.setLabelText(_("Printing page {page} ({num} of {total})...").format(
page=page, num=num, total=total))
def finished():
p.deleteLater()
d.deleteLater()
d.hide()
#.........这里部分代码省略.........
示例2: print_
# 需要导入模块: from PyQt4.QtGui import QPrintDialog [as 别名]
# 或者: from PyQt4.QtGui.QPrintDialog import setOption [as 别名]
def print_(doc, filename=None, widget=None):
"""Prints the popplerqt4.Poppler.Document.
The filename is used in the dialog and print job name.
If the filename is not given, it defaults to a translation of "PDF Document".
The widget is a widget to use as parent for the print dialog etc.
"""
cmd = fileprinter.lprCommand()
if not cmd and QMessageBox.information(widget, _("Warning"), _(
"No print command to print a PostScript file could be found.\n\n"
"Therefore the document will be printed using raster images at {resolution} DPI. "
"It is recommended to print using a dedicated PDF viewer.\n\n"
"Do you want to continue?").format(resolution=300),
QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
return # cancelled
filename = os.path.basename(filename) if filename else _("PDF Document")
printer = QPrinter()
printer.setDocName(filename)
dlg = QPrintDialog(printer, widget)
dlg.setMinMax(1, doc.numPages())
dlg.setOption(QPrintDialog.PrintToFile, False)
dlg.setWindowTitle(app.caption(_("Print {filename}").format(filename=filename)))
result = dlg.exec_()
if widget:
dlg.deleteLater() # because it has a parent
if not result:
return # cancelled
if cmd:
# make a PostScript file with the desired paper size
ps = QTemporaryFile()
if ps.open() and qpopplerview.printer.psfile(doc, printer, ps):
ps.close()
# let all converted pages print
printer.setPrintRange(QPrinter.AllPages)
command = fileprinter.printCommand(cmd, printer, ps.fileName())
if not subprocess.call(command):
return # success!
QMessageBox.warning(widget, _("Printing Error"),
_("Could not send the document to the printer."))
else:
# Fall back printing of rendered raster images.
# It is unsure if the Poppler ArthurBackend ever will be ready for
# good rendering directly to a painter, so we'll fall back to using
# 300DPI raster images.
p = Printer()
p.setDocument(doc)
p.setPrinter(printer)
p.setResolution(300)
d = QProgressDialog()
d.setModal(True)
d.setMinimumDuration(0)
d.setRange(0, len(p.pageList()) + 1)
d.canceled.connect(p.abort)
def progress(num, total, page):
d.setValue(num)
d.setLabelText(_("Printing page {page} ({num} of {total})...").format(
page=page, num=num, total=total))
def finished():
p.deleteLater()
d.deleteLater()
d.hide()
if not p.success and not p.aborted():
QMessageBox.warning(widget, _("Printing Error"),
_("Could not send the document to the printer."))
p.finished.connect(finished)
p.printing.connect(progress)
p.start()