本文整理汇总了Python中PyQt4.QtGui.QPrinter.setColorMode方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.setColorMode方法的具体用法?Python QPrinter.setColorMode怎么用?Python QPrinter.setColorMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QPrinter
的用法示例。
在下文中一共展示了QPrinter.setColorMode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _exportCompositionAsPDF
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setColorMode [as 别名]
def _exportCompositionAsPDF(self,composition,filePath):
"""
Render the composition as a PDF file.
"""
printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(filePath)
printer.setPaperSize(QSizeF(composition.paperWidth(),composition.paperHeight()),QPrinter.Millimeter)
printer.setFullPage(True)
printer.setColorMode(QPrinter.Color)
printer.setResolution(composition.printResolution())
#Use painter to send output to printer
pdfPainter = QPainter(printer)
paperRectMM = printer.pageRect(QPrinter.Millimeter)
paperRectPixel = printer.pageRect(QPrinter.DevicePixel)
composition.render(pdfPainter,paperRectPixel,paperRectMM)
pdfPainter.end()
示例2: BatchPlottingDialog
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setColorMode [as 别名]
#.........这里部分代码省略.........
return
if not self.ui.SingleFileCheckbox.checkState():
multiFilePrinter = QPrinter()
outputFileName = QDir( outputDir ).filePath( atlas.currentFilename() ) + ".pdf"
self.composition.beginPrintAsPDF( multiFilePrinter, outputFileName )
# set the correct resolution
self.composition.beginPrint( multiFilePrinter )
printReady = painter.begin( multiFilePrinter )
if not printReady:
QMessageBox.warning( self, tr( "Atlas processing error" ),
tr( "Error creating %s." % outputFileName ) )
progress.cancel()
QApplication.restoreOverrideCursor()
return
self.composition.doPrint( multiFilePrinter, painter )
painter.end()
else:
# start print on a new page if we're not on the first feature
if featureI > 0:
printer.newPage()
self.composition.doPrint( printer, painter )
atlas.endRender()
if self.ui.SingleFileCheckbox.checkState():
painter.end()
QApplication.restoreOverrideCursor()
elif self.ui.OutputTab.currentIndex() == 1: # to Printer
# if To Printer is selected set the printer
# setting up printer
if self.printer is None:
self.printer = QPrinter()
self.printer.setFullPage(True)
self.printer.setColorMode(QPrinter.Color)
# open printer setting dialog
pdlg = QPrintDialog(self.printer,self)
pdlg.setModal(True)
pdlg.setOptions(QAbstractPrintDialog.None)
if not pdlg.exec_() == QDialog.Accepted:
return
QApplication.setOverrideCursor(Qt.BusyCursor)
#prepare for first feature, so that we know paper size to begin with
self.composition.setAtlasMode( QgsComposition.ExportAtlas )
atlas.prepareForFeature(0)
# set orientation
if self.composition.paperWidth() > self.composition.paperHeight():
self.printer.setOrientation(QPrinter.Landscape)
self.printer.setPaperSize(
QSizeF(self.composition.paperHeight(), self.composition.paperWidth()),
QPrinter.Millimeter)
else:
self.printer.setOrientation(QPrinter.Portrait)
self.printer.setPaperSize(
QSizeF(self.composition.paperWidth(), self.composition.paperHeight()),
QPrinter.Millimeter)
self.printer.setResolution(self.composition.printResolution())
self.composition.beginPrint( self.printer )
painter = QPainter(self.printer)
if not len(atlas.featureFilterErrorString()) == 0:
QMessageBox.warning( self, tr( "Atlas processing error" ),
tr( "Feature filter parser error: %s" % atlas.featureFilterErrorString() ) )
QApplication.restoreOverrideCursor()
return
示例3: export_all_features
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setColorMode [as 别名]
#.........这里部分代码省略.........
new_ext.setYMaximum(bbox.yMaximum() + delta_height / 2)
else:
new_width = old_ratio * new_ext.height()
delta_width = new_width - new_ext.width()
new_ext.setXMinimum(bbox.xMinimum() - delta_width / 2)
new_ext.setXMaximum(bbox.xMaximum() + delta_width / 2)
if VRP_DEBUG is True: QgsMessageLog.logMessage(u'bbox old:{0}'.format(compmap.extent().toString()), DLG_CAPTION)
compmap.setNewExtent(new_ext)
if VRP_DEBUG is True: QgsMessageLog.logMessage(u'bbox new:{0}'.format(compmap.extent().toString()), DLG_CAPTION)
#round up to next 1000
compmap.setNewScale(math.ceil((compmap.scale()/1000.0)) * 1000.0)
if VRP_DEBUG is True: QgsMessageLog.logMessage(u'bbox new (after scale):{0}'.format(compmap.extent().toString()), DLG_CAPTION)
#add ORTHO after new extent -> performance
if not self.ortho is None:
self.ortho_lyr = self.__add_raster_layer(self.ortho, self.lyrname_ortho)
self.__reorder_layers()
self.comp_leg = self.__get_items(QgsComposerLegend)
self.comp_lbl = self.__get_items(QgsComposerLabel)
self.__update_composer_items(self.settings.dkm_gemeinde(self.gem_name)['lyrnamegstk'])
if VRP_DEBUG is True:
QgsMessageLog.logMessage(u'paperWidth:{0} paperHeight:{1}'.format(composition.paperWidth(), composition.paperHeight()), DLG_CAPTION)
printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(self.pdf_map)
printer.setPaperSize(QSizeF(composition.paperWidth(), composition.paperHeight()), QPrinter.Millimeter)
printer.setFullPage(True)
printer.setColorMode(QPrinter.Color)
printer.setResolution(composition.printResolution())
pdf_painter = QPainter(printer)
paper_rect_pixel = printer.pageRect(QPrinter.DevicePixel)
paper_rect_mm = printer.pageRect(QPrinter.Millimeter)
QgsPaintEngineHack.fixEngineFlags(printer.paintEngine())
#DKM only
if len(self.themen) < 1:
composition.render(pdf_painter, paper_rect_pixel, paper_rect_mm)
else:
self.statistics = OrderedDict()
try:
pass
#lyr = QgsVectorLayer('/home/bergw/VoGIS-Raumplanung-Daten/Geodaten/Raumplanung/Flaechenwidmung/Dornbirn/Flaechenwidmungsplan/fwp_flaeche.shp', 'flaeiw', 'ogr')
#lyr.loadNamedStyle('/home/bergw/VoGIS-Raumplanung-Daten/Geodaten/Raumplanung/Flaechenwidmung/Vorarlberg/Flaechenwidmungsplan/fwp_flaeche.qml')
#QgsMapLayerRegistry.instance().addMapLayer(lyr)
except:
QgsMessageLog.logMessage('new lyr:{0}'.format(sys.exc_info()[0]), DLG_CAPTION)
#QgsMapLayerRegistry.instance().addMapLayer(lyr)
cntr = 0
for thema, sub_themen in self.themen.iteritems():
if VRP_DEBUG is True: QgsMessageLog.logMessage('drucke Thema:{0}'.format(thema.name), DLG_CAPTION)
if sub_themen is None:
layers = self.__add_layers(thema)
self.__calculate_statistics(thema, thema, layers)
#no qml -> not visible -> means no map
if self.__at_least_one_visible(layers) is True:
if cntr > 0:
printer.newPage()
self.__reorder_layers()
self.__update_composer_items(thema.name, layers=layers)
composition.renderPage(pdf_painter, 0)
示例4: _get_composer_pdf_image
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setColorMode [as 别名]
def _get_composer_pdf_image(self, width, height, dpi):
pdfpath = getTempfilePath('pdf')
temp_size = os.path.getsize(pdfpath)
p = QPrinter()
p.setOutputFormat(QPrinter.PdfFormat)
p.setOutputFileName(pdfpath)
p.setPaperSize(QSizeF(self._c.paperWidth(), self._c.paperHeight()),
QPrinter.Millimeter)
p.setFullPage(True)
p.setColorMode(QPrinter.Color)
p.setResolution(self._c.printResolution())
pdf_p = QPainter(p)
# page_mm = p.pageRect(QPrinter.Millimeter)
# page_px = p.pageRect(QPrinter.DevicePixel)
# self._c.render(pdf_p, page_px, page_mm)
self._c.renderPage(pdf_p, 0)
pdf_p.end()
if temp_size == os.path.getsize(pdfpath):
return False, ''
filepath = getTempfilePath('png')
# Poppler (pdftocairo or pdftoppm):
# PDFUTIL -png -singlefile -r 72 -x 0 -y 0 -W 420 -H 280 in.pdf pngbase
# muPDF (mudraw):
# PDFUTIL -c rgb[a] -r 72 -w 420 -h 280 -o out.png in.pdf
if PDFUTIL.strip().endswith('pdftocairo'):
filebase = os.path.join(
os.path.dirname(filepath),
os.path.splitext(os.path.basename(filepath))[0]
)
call = [
PDFUTIL, '-png', '-singlefile', '-r', str(dpi),
'-x', '0', '-y', '0', '-W', str(width), '-H', str(height),
pdfpath, filebase
]
elif PDFUTIL.strip().endswith('mudraw'):
call = [
PDFUTIL, '-c', 'rgba',
'-r', str(dpi), '-w', str(width), '-h', str(height),
# '-b', '8',
'-o', filepath, pdfpath
]
else:
return False, ''
qDebug("_get_composer_pdf_image call: {0}".format(' '.join(call)))
res = False
try:
subprocess.check_call(call)
res = True
except subprocess.CalledProcessError as e:
qDebug("_get_composer_pdf_image failed!\n"
"cmd: {0}\n"
"returncode: {1}\n"
"message: {2}".format(e.cmd, e.returncode, e.message))
if not res:
os.unlink(filepath)
filepath = ''
return res, filepath
示例5: QPrinter
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setColorMode [as 别名]
compmap.setPreviewMode(QgsComposerMap.Render)
#compmap.updateItem()
#emit compmap.itemChanged();
#compmap.extentChanged();
#compmap.toggleAtlasPreview()
#compmap.setNewScale(compmap.scale()+1)
#c.setPrintResolution(150)
#print c.printResolution()
c.setPrintAsRaster(False)
printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(pdf_out)
printer.setPaperSize(QSizeF(c.paperWidth(), c.paperHeight()), QPrinter.Millimeter)
printer.setFullPage(True)
printer.setColorMode(QPrinter.Color)
printer.setResolution(c.printResolution())
pdfPainter = QPainter(printer)
paperRectMM = printer.pageRect(QPrinter.Millimeter)
paperRectPixel = printer.pageRect(QPrinter.DevicePixel)
QgsPaintEngineHack.fixEngineFlags(printer.paintEngine())
#c.renderPage(pdfPainter, 0)
c.doPrint(printer,pdfPainter)
pdfPainter.end()
subprocess.call(('xdg-open', pdf_out))
print 'FERTIG'