本文整理汇总了Python中PyQt5.QtPrintSupport.QPrintDialog.setWindowTitle方法的典型用法代码示例。如果您正苦于以下问题:Python QPrintDialog.setWindowTitle方法的具体用法?Python QPrintDialog.setWindowTitle怎么用?Python QPrintDialog.setWindowTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtPrintSupport.QPrintDialog
的用法示例。
在下文中一共展示了QPrintDialog.setWindowTitle方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_webpage
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [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.
"""
if self.print_settings.get("mode") == "high":
printer = QPrinter(mode=QPrinter.HighResolution)
else:
printer = QPrinter(mode=QPrinter.ScreenResolution)
if self.print_settings:
if self.print_settings.get("size_unit"):
try:
unit = getattr(
QPrinter,
self.print_settings.get("size_unit").capitalize()
)
except NameError:
debug(
"Specified print size unit '{}' not found,"
"using default.".format(
self.print_settings.get("size_unit")
))
unit = QPrinter.Millimeter
else:
unit = QPrinter.Millimeter
margins = (
list(self.print_settings.get("margins"))
or list(printer.getPageMargins(unit))
)
margins += [unit]
printer.setPageMargins(*margins)
if self.print_settings.get("orientation") == "landscape":
printer.setOrientation(QPrinter.Landscape)
else:
printer.setOrientation(QPrinter.Portrait)
if self.print_settings.get("paper_size"):
printer.setPaperSize(QSizeF(
*self.print_settings.get("paper_size")
), unit)
if self.print_settings.get("resolution"):
printer.setResolution(
int(self.print_settings.get("resolution"))
)
if not self.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
示例2: printFile
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def printFile(self):
self.currentTab.updatePreviewBox()
printer = self.standardPrinter()
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle(self.tr("Print document"))
if (dlg.exec() == QDialog.Accepted):
document = self.getDocumentForPrint()
if document != None:
document.print(printer)
示例3: printFile
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def printFile(self):
title, htmltext, preview = self.currentTab.getDocumentForExport(includeStyleSheet=True,
webenv=False)
printer = self.standardPrinter(title)
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle(self.tr("Print document"))
if (dlg.exec() == QDialog.Accepted):
document = self.getDocumentForPrint(title, htmltext, preview)
if document != None:
document.print(printer)
示例4: print_
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def print_(self):
printer = QPrinter()
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle(app.caption(_("Print")))
options = (QAbstractPrintDialog.PrintToFile
| QAbstractPrintDialog.PrintShowPageSize
| QAbstractPrintDialog.PrintPageRange)
if self.browser.textCursor().hasSelection():
options |= QAbstractPrintDialog.PrintSelection
dlg.setOptions(options)
if dlg.exec_():
self.browser.print_(printer)
示例5: print
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def print(self):
print("controller.print")
editor = self.ui.webView
printer = QPrinter()
#print(printer, self)
dialog = QPrintDialog(printer, self)
dialog.setWindowTitle("Print Document")
if dialog.exec_() != QDialog.Accepted:
return
editor.print_(printer)
示例6: filePrint
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def filePrint(self):
printer = QPrinter(QPrinter.HighResolution)
dlg = QPrintDialog(printer, self)
if self.textEdit.textCursor().hasSelection():
dlg.addEnabledOption(QPrintDialog.PrintSelection)
dlg.setWindowTitle("Print Document")
if dlg.exec_() == QPrintDialog.Accepted:
self.textEdit.print_(printer)
del dlg
示例7: printFile
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def printFile(self):
editor = self.letters.currentWidget()
printer = QPrinter()
dialog = QPrintDialog(printer, self)
dialog.setWindowTitle("Print Document")
if editor.textCursor().hasSelection():
dialog.addEnabledOption(QAbstractPrintDialog.PrintSelection)
if dialog.exec_() != QDialog.Accepted:
return
editor.print_(printer)
示例8: printFile
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def printFile(self):
editor = self.solvers.currentWidget()
if type(editor) == QTextEdit:
printer = QPrinter()
dialog = QPrintDialog(printer, self)
dialog.setWindowTitle("Print Document")
if dialog.exec_() != QDialog.Accepted:
return
editor.print_(printer)
else:
answer = QMessageBox.warning(self, "Not Print Image",
"Dont print graph.",
QMessageBox.Ok)
示例9: printSource
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def printSource(self):
cursor = self.textCursor()
try:
printer = self._sourcePrinter
except AttributeError:
printer = self._sourcePrinter = QPrinter()
else:
printer.setCopyCount(1)
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle(app.caption(_("dialog title", "Print Source")))
options = QAbstractPrintDialog.PrintToFile | QAbstractPrintDialog.PrintShowPageSize
if cursor.hasSelection():
options |= QAbstractPrintDialog.PrintSelection
dlg.setOptions(options)
if dlg.exec_():
if dlg.printRange() != QAbstractPrintDialog.Selection:
cursor.clearSelection()
number_lines = QSettings().value("source_export/number_lines", False, bool)
doc = highlighter.html_copy(cursor, 'printer', number_lines)
doc.setMetaInformation(QTextDocument.DocumentTitle, self.currentDocument().url().toString())
font = doc.defaultFont()
font.setPointSizeF(font.pointSizeF() * 0.8)
doc.setDefaultFont(font)
doc.print_(printer)
示例10: slotPrint
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def slotPrint(self):
printer = QPrinter()
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle(app.caption(_("Print")))
if dlg.exec_():
self.webview.print_(printer)
示例11: print_webpage
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [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
示例12: print_
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def print_(doc, filename=None, widget=None):
"""Prints the popplerqt5.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", "", str)
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")
if widget:
try:
printer = _printers[widget]
except KeyError:
printer = _printers[widget] = QPrinter()
else:
printer.setCopyCount(1)
else:
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)
#.........这里部分代码省略.........
示例13: printImage
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import setWindowTitle [as 别名]
def printImage(self):
if self.model.rowCount(QModelIndex()) * self.model.columnCount(QModelIndex()) > 90000:
answer = QMessageBox.question(self, "Large Image Size",
"The printed image may be very large. Are you sure that "
"you want to print it?",
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.No:
return
printer = QPrinter(QPrinter.HighResolution)
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle("Print Image")
if dlg.exec_() != QDialog.Accepted:
return
painter = QPainter()
painter.begin(printer)
rows = self.model.rowCount(QModelIndex())
columns = self.model.columnCount(QModelIndex())
sourceWidth = (columns+1) * ItemSize
sourceHeight = (rows+1) * ItemSize
painter.save()
xscale = printer.pageRect().width() / float(sourceWidth)
yscale = printer.pageRect().height() / float(sourceHeight)
scale = min(xscale, yscale)
painter.translate(printer.paperRect().x()+printer.pageRect().width()/2,
printer.paperRect().y()+printer.pageRect().height()/2)
painter.scale(scale, scale)
painter.translate(-sourceWidth/2, -sourceHeight/2)
option = QStyleOptionViewItem()
parent = QModelIndex()
progress = QProgressDialog("Printing...", "Cancel", 0, rows, self)
progress.setWindowModality(Qt.ApplicationModal)
y = ItemSize / 2.0
for row in range(rows):
progress.setValue(row)
QApplication.processEvents()
if progress.wasCanceled():
break
x = ItemSize / 2.0
for column in range(columns):
option.rect = QRect(x, y, ItemSize, ItemSize)
self.view.itemDelegate().paint(painter, option,
self.model.index(row, column, parent))
x += ItemSize
y += ItemSize
progress.setValue(rows)
painter.restore()
painter.end()
if progress.wasCanceled():
QMessageBox.information(self, "Printing canceled",
"The printing process was canceled.", QMessageBox.Cancel)