本文整理汇总了Python中PyQt5.QtPrintSupport.QPrinter.printerName方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.printerName方法的具体用法?Python QPrinter.printerName怎么用?Python QPrinter.printerName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtPrintSupport.QPrinter
的用法示例。
在下文中一共展示了QPrinter.printerName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __printImage
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import printerName [as 别名]
def __printImage(self):
"""
Private slot to handle the Print Image menu action.
"""
if self.mainWidget is None:
E5MessageBox.critical(
self,
self.tr("Print Image"),
self.tr("""There is no UI file loaded."""))
return
settings = Preferences.Prefs.settings
printer = QPrinter(QPrinter.HighResolution)
printer.setFullPage(True)
printerName = Preferences.getPrinter("UIPreviewer/printername")
if printerName:
printer.setPrinterName(printerName)
printer.setPageSize(
QPrinter.PageSize(int(settings.value("UIPreviewer/pagesize"))))
printer.setPageOrder(
QPrinter.PageOrder(int(settings.value("UIPreviewer/pageorder"))))
printer.setOrientation(QPrinter.Orientation(
int(settings.value("UIPreviewer/orientation"))))
printer.setColorMode(
QPrinter.ColorMode(int(settings.value("UIPreviewer/colormode"))))
printDialog = QPrintDialog(printer, self)
if printDialog.exec_() == QDialog.Accepted:
self.statusBar().showMessage(self.tr("Printing the image..."))
self.__print(printer)
settings.setValue("UIPreviewer/printername", printer.printerName())
settings.setValue("UIPreviewer/pagesize", printer.pageSize())
settings.setValue("UIPreviewer/pageorder", printer.pageOrder())
settings.setValue("UIPreviewer/orientation", printer.orientation())
settings.setValue("UIPreviewer/colormode", printer.colorMode())
self.statusBar().showMessage(
self.tr("Image sent to printer..."), 2000)
示例2: PrinterPyQt5
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import printerName [as 别名]
class PrinterPyQt5(Printer):
def __init__(self, page_size, print_pdf=False):
super().__init__(page_size)
self._printer = QPrinter(QPrinter.HighResolution)
self._printer.setPageSize(QtGui.QPageSize(QtCore.QSizeF(*page_size),
QtGui.QPageSize.Millimeter))
self._printer.setColorMode(QPrinter.Color)
logging.info('Using printer "%s"', self._printer.printerName())
self._print_pdf = print_pdf
if self._print_pdf:
logging.info('Using PDF printer')
self._counter = 0
self._printer.setOutputFormat(QPrinter.PdfFormat)
self._printer.setFullPage(True)
def print(self, picture):
if self._print_pdf:
self._printer.setOutputFileName('print_%d.pdf' % self._counter)
self._counter += 1
logging.info('Printing picture')
picture = picture.scaled(self._printer.paperRect().size(),
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
printable_size = self._printer.pageRect(QPrinter.DevicePixel)
origin = ((printable_size.width() - picture.width()) // 2,
(printable_size.height() - picture.height()) // 2)
painter = QtGui.QPainter(self._printer)
painter.drawImage(QtCore.QPoint(*origin), picture)
painter.end()
示例3: print_webpage
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import printerName [as 别名]
def print_webpage(self):
"""Print the webpage to a printer.
Callback for the print action.
Should show a print dialog and print the webpage to the printer.
"""
print_settings = self.config.get("print_settings", {})
if print_settings.get("mode") == "high":
printer = QPrinter(mode=QPrinter.HighResolution)
else:
printer = QPrinter(mode=QPrinter.ScreenResolution)
# set which printer
# FIXME: This isn't documented, because it doesn't seem to work...
if print_settings.get("printer_name"):
debug(
"Setting printer to: {}".format(
print_settings.get("printer_name"))
)
printer.setPrinterName(print_settings.get("printer_name"))
debug("Printer is now: {}".format(printer.printerName()))
# Set the units
unit_name = print_settings.get("size_unit", 'Millimeter').title()
try:
unit = getattr(QPrinter, unit_name)
except AttributeError:
debug(
"Specified print size unit '{}' not found, using default."
.format(unit_name)
)
unit = QPrinter.Millimeter
# Set the margins
margins = list(
print_settings.get("margins", printer.getPageMargins(unit))
)
margins.append(unit)
printer.setPageMargins(*margins)
# Set the Orientation
orientation = print_settings.get("orientation", 'Portrait').title()
printer.setOrientation(
getattr(QPrinter, orientation, QPrinter.Portrait)
)
# Set the paper size
paper_size = print_settings.get("paper_size")
if type(paper_size) in (list, tuple):
# Assume it's a width/height spec
printer.setPaperSize(QSizeF(*paper_size), unit)
elif paper_size is not None: # Assume it's a size name
printer.setPaperSize(getattr(QPrinter, paper_size, 'AnsiA'))
# If paper_size is None, we just leave it at the printer's default
# Set the resolution
resolution = print_settings.get("resolution")
if resolution:
printer.setResolution(int(resolution))
# Show a print dialog, unless we want silent printing
if not print_settings.get("silent"):
print_dialog = QPrintDialog(printer, self)
print_dialog.setWindowTitle("Print Page")
if not print_dialog.exec_() == QDialog.Accepted:
return False
self.print_(printer)
return True