本文整理汇总了Python中PyQt4.QtGui.QPrinter.setNumCopies方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.setNumCopies方法的具体用法?Python QPrinter.setNumCopies怎么用?Python QPrinter.setNumCopies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QPrinter
的用法示例。
在下文中一共展示了QPrinter.setNumCopies方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: printFiles
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setNumCopies [as 别名]
def printFiles(fileNames, printer):
"""Prints a list of files (PS or PDF) via a printer command.
The printer command is constructed by quering the QPrinter object.
If there is more than one PDF file, print to file should have been disabled
in the QPrintDialog that configured the printer.
"""
output = printer.outputFileName()
if output:
# Print to File, determine suffixes, assume one file
fileName = fileNames[0]
inext, outext = (os.path.splitext(name)[1].lower() for name in (fileName, output))
if inext == outext:
# just copy
shutil.copyfile(fileName, output)
else:
cmd = "pdf2ps" if outext == ".ps" else "ps2pdf"
try:
ret = subprocess.call([cmd, fileName, output])
if ret:
raise CommandFailed(KShell.joinArgs([cmd, fileName, output]), ret)
except OSError:
raise CommandNotFound(cmd)
return
# print to a printer
cmd = []
# Which exe?
for exe in "lpr-cups", "lpr.cups", "lpr", "lp":
if KStandardDirs.findExe(exe):
break
else:
raise NoPrintCommandFound()
cmd.append(exe)
# Add the arguments.
# printer name
if exe == "lp":
cmd.append("-d")
else:
cmd.append("-P")
cmd.append(printer.printerName())
# helper for adding (Cups) options to the command line
def option(s):
cmd.append("-o")
cmd.append(s)
# copies
try:
copies = printer.actualNumCopies()
except AttributeError: # only available in Qt >= 4.6
copies = printer.numCopies()
if exe == "lp":
cmd.append("-n")
cmd.append(format(copies))
else:
cmd.append("-#{0}".format(copies))
# job name
if printer.docName():
if exe == "lp":
cmd.append("-t")
cmd.append(printer.docName())
elif exe.startswith("lpr"):
cmd.append("-J")
cmd.append(printer.docName())
# page range
if printer.printRange() == QPrinter.PageRange:
pageRange = "{0}-{1}".format(printer.fromPage(), printer.toPage())
if exe == "lp":
cmd.append("-P")
cmd.append(pageRange)
else:
option("page-ranges={0}".format(pageRange))
# CUPS-specific options; detect if CUPS is available.
test = QPrinter()
test.setNumCopies(2)
cups = test.numCopies() == 1
if cups:
# media, size etc.
media = []
size = printer.paperSize()
if size == QPrinter.Custom:
media.append("Custom.{0}x{1}mm".format(printer.heightMM(), printer.widthMM()))
elif size in PAGE_SIZES:
media.append(PAGE_SIZES[size])
# media source
source = printer.paperSource()
#.........这里部分代码省略.........