本文整理汇总了Python中utilities.getTempfilePath函数的典型用法代码示例。如果您正苦于以下问题:Python getTempfilePath函数的具体用法?Python getTempfilePath怎么用?Python getTempfilePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getTempfilePath函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_composer_pdf_image
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):
# something went pear-shaped
return False, ''
filepath = getTempfilePath('png')
# pdftoppm -singlefile -r 72 -x 0 -y 0 -W 600 -H 400 -png in.pdf pngbase
# mudraw -o out.png -r 72 -w 600 -h 400 -c rgb[a] in.pdf
if PDFUTIL == 'pdftoppm':
filebase = os.path.join(
os.path.dirname(filepath),
os.path.splitext(os.path.basename(filepath))[0]
)
call = [
'pdftoppm', '-singlefile', '-r', str(dpi),
'-x', str(0), '-y', str(0), '-W', str(width), '-H', str(height),
'-png', pdfpath, filebase
]
elif PDFUTIL == 'mudraw':
call = [
'mudraw', '-c', 'rgba',
'-r', str(dpi), '-w', str(width), '-h', str(height),
'-o', filepath, pdfpath
]
else:
return False, ''
res = subprocess.check_call(call)
if not res:
os.unlink(filepath)
filepath = ''
return res, filepath
开发者ID:MERIDIAN-CHARTWARE,项目名称:QGIS-1,代码行数:53,代码来源:test_qgspallabeling_composer.py
示例2: run_suite
def run_suite(module, tests):
"""This allows for a list of test names to be selectively run.
Also, ensures unittest verbose output comes at end, after debug output"""
loader = unittest.defaultTestLoader
if 'QGIS_TEST_SUITE' in os.environ and tests:
suite = loader.loadTestsFromNames(tests, module)
else:
suite = loader.loadTestsFromModule(module)
verb = 2 if 'QGIS_TEST_VERBOSE' in os.environ else 0
res = unittest.TextTestRunner(verbosity=verb).run(suite)
if QGIS_TEST_REPORT and len(TESTREPORTS) > 0:
teststamp = 'Local Server Test Report: ' + \
datetime.datetime.now().strftime('%Y-%m-%d %X')
report = '<html><head><title>{0}</title></head><body>'.format(teststamp)
report += '\n<h2>Failed Image Tests: {0}</h2>'.format(len(TESTREPORTS))
for k, v in list(TESTREPORTS.items()):
report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
report += '</body></html>'
tmp_name = getTempfilePath("html")
with open(tmp_name, 'wb') as temp_file:
temp_file.write(report)
openInBrowserTab('file://' + tmp_name)
return res
开发者ID:liminlu0314,项目名称:QGIS,代码行数:27,代码来源:test_qgis_local_server.py
示例3: checkTest
def checkTest(self, **kwargs):
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))
ms = self._MapSettings # class settings
settings_type = 'Class'
if self._TestMapSettings is not None:
ms = self._TestMapSettings # per test settings
settings_type = 'Test'
if 'PAL_VERBOSE' in os.environ:
qDebug('MapSettings type: {0}'.format(settings_type))
qDebug(mapSettingsString(ms))
img = renderMapToImage(ms, parallel=False)
self._TestImage = getTempfilePath('png')
if not img.save(self._TestImage, 'png'):
os.unlink(self._TestImage)
raise OSError('Failed to save output from map render job')
self.saveControlImage(self._TestImage)
mismatch = 0
if 'PAL_NO_MISMATCH' not in os.environ:
# some mismatch expected
mismatch = self._Mismatch if self._Mismatch else 0
if self._TestGroup in self._Mismatches:
mismatch = self._Mismatches[self._TestGroup]
colortol = 0
if 'PAL_NO_COLORTOL' not in os.environ:
colortol = self._ColorTol if self._ColorTol else 0
if self._TestGroup in self._ColorTols:
colortol = self._ColorTols[self._TestGroup]
self.assertTrue(*self.renderCheck(mismatch=mismatch,
colortol=colortol,
imgpath=self._TestImage))
开发者ID:giohappy,项目名称:QGIS,代码行数:33,代码来源:test_qgspallabeling_canvas.py
示例4: runSuite
def runSuite(module, tests):
"""This allows for a list of test names to be selectively run.
Also, ensures unittest verbose output comes at end, after debug output"""
loader = unittest.defaultTestLoader
if 'PAL_SUITE' in os.environ:
if tests:
suite = loader.loadTestsFromNames(tests, module)
else:
raise Exception(
"\n\n####__ 'PAL_SUITE' set, but no tests specified __####\n")
else:
suite = loader.loadTestsFromModule(module)
verb = 2 if 'PAL_VERBOSE' in os.environ else 0
res = unittest.TextTestRunner(verbosity=verb).run(suite)
if PALREPORTS:
teststamp = 'PAL Test Report: ' + \
datetime.datetime.now().strftime('%Y-%m-%d %X')
report = '<html><head><title>{0}</title></head><body>'.format(teststamp)
report += '\n<h2>Failed Tests: {0}</h2>'.format(len(PALREPORTS))
for k, v in list(PALREPORTS.items()):
report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
report += '</body></html>'
tmp_name = getTempfilePath('html')
with open(tmp_name, 'wt') as report_file:
report_file.write(report)
openInBrowserTab('file://' + tmp_name)
return res
开发者ID:GrokImageCompression,项目名称:QGIS,代码行数:31,代码来源:test_qgspallabeling_base.py
示例5: checkTest
def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
ms = self._MapSettings # class settings
settings_type = "Class"
if self._TestMapSettings is not None:
ms = self._TestMapSettings # per test settings
settings_type = "Test"
if "PAL_VERBOSE" in os.environ:
qDebug("MapSettings type: {0}".format(settings_type))
qDebug(mapSettingsString(ms))
img = renderMapToImage(ms, parallel=False)
self._TestImage = getTempfilePath("png")
if not img.save(self._TestImage, "png"):
os.unlink(self._TestImage)
raise OSError("Failed to save output from map render job")
self.saveControlImage(self._TestImage)
mismatch = 0
if "PAL_NO_MISMATCH" not in os.environ:
# some mismatch expected
mismatch = self._Mismatch if self._Mismatch else 0
if self._TestGroup in self._Mismatches:
mismatch = self._Mismatches[self._TestGroup]
colortol = 0
if "PAL_NO_COLORTOL" not in os.environ:
colortol = self._ColorTol if self._ColorTol else 0
if self._TestGroup in self._ColorTols:
colortol = self._ColorTols[self._TestGroup]
self.assertTrue(*self.renderCheck(mismatch=mismatch, colortol=colortol, imgpath=self._TestImage))
开发者ID:GrokImageCompression,项目名称:QGIS,代码行数:31,代码来源:test_qgspallabeling_placement.py
示例6: _get_composer_image
def _get_composer_image(self, width, height, dpi):
# image = QImage(QSize(width, height), QImage.Format_ARGB32)
# image.fill(QColor(152, 219, 249).rgb())
# image.setDotsPerMeterX(dpi / 25.4 * 1000)
# image.setDotsPerMeterY(dpi / 25.4 * 1000)
#
# p = QPainter(image)
# p.setRenderHint(QPainter.Antialiasing, False)
# p.setRenderHint(QPainter.HighQualityAntialiasing, False)
# self._c.renderPage(p, 0)
# p.end()
image = self._c.printPageAsRaster(0)
""":type: QImage"""
if image.isNull():
return False, ''
filepath = getTempfilePath('png')
res = image.save(filepath, 'png')
if not res:
os.unlink(filepath)
filepath = ''
return res, filepath
开发者ID:glubbered,项目名称:QGIS,代码行数:25,代码来源:test_qgspallabeling_composer.py
示例7: _get_composer_svg_image
def _get_composer_svg_image(self, width, height, dpi):
# from qgscomposer.cpp, QgsComposer::on_mActionExportAsSVG_triggered,
# line 1909, near end of function
svgpath = getTempfilePath('svg')
temp_size = os.path.getsize(svgpath)
svg_g = QSvgGenerator()
# noinspection PyArgumentList
svg_g.setTitle(QgsProject.instance().title())
svg_g.setFileName(svgpath)
# width and height in pixels
# svg_w = int(self._c.paperWidth() * self._c.printResolution() / 25.4)
# svg_h = int(self._c.paperHeight() * self._c.printResolution() / 25.4)
svg_w = width
svg_h = height
svg_g.setSize(QSize(svg_w, svg_h))
svg_g.setViewBox(QRect(0, 0, svg_w, svg_h))
# because the rendering is done in mm, convert the dpi
# svg_g.setResolution(self._c.printResolution())
svg_g.setResolution(dpi)
sp = QPainter(svg_g)
self._c.renderPage(sp, 0)
sp.end()
if temp_size == os.path.getsize(svgpath):
# something went pear-shaped
return False, ''
image = QImage(width, height, QImage.Format_ARGB32)
image.fill(QColor(152, 219, 249).rgb())
image.setDotsPerMeterX(dpi / 25.4 * 1000)
image.setDotsPerMeterY(dpi / 25.4 * 1000)
svgr = QSvgRenderer(svgpath)
p = QPainter(image)
svgr.render(p)
p.end()
filepath = getTempfilePath('png')
res = image.save(filepath, 'png')
if not res:
os.unlink(filepath)
filepath = ''
# TODO: remove .svg file as well?
return res, filepath
开发者ID:MERIDIAN-CHARTWARE,项目名称:QGIS-1,代码行数:47,代码来源:test_qgspallabeling_composer.py
示例8: saveControlImage
def saveControlImage(self, tmpimg=''):
# don't save control images for RenderVsOtherOutput (Vs) tests, since
# those control images belong to a different test result
if ('PAL_CONTROL_IMAGE' not in os.environ
or 'Vs' in self._TestGroup):
return
imgpath = self.controlImagePath()
testdir = os.path.dirname(imgpath)
if not os.path.exists(testdir):
os.makedirs(testdir)
imgbasepath = \
os.path.join(testdir,
os.path.splitext(os.path.basename(imgpath))[0])
# remove any existing control images
for f in glob.glob(imgbasepath + '.*'):
if os.path.exists(f):
os.remove(f)
qDebug('Control image for {0}.{1}'.format(self._TestGroup,
self._TestFunction))
if not tmpimg:
# TODO: this can be deprecated, when per-base-test-class rendering
# in checkTest() is verified OK for all classes
qDebug('Rendering control to: {0}'.format(imgpath))
ms = self._MapSettings # class settings
""":type: QgsMapSettings"""
settings_type = 'Class'
if self._TestMapSettings is not None:
ms = self._TestMapSettings # per test settings
settings_type = 'Test'
qDebug('MapSettings type: {0}'.format(settings_type))
img = renderMapToImage(ms, parallel=False)
""":type: QImage"""
tmpimg = getTempfilePath('png')
if not img.save(tmpimg, 'png'):
os.unlink(tmpimg)
raise OSError('Control not created for: {0}'.format(imgpath))
if tmpimg and os.path.exists(tmpimg):
qDebug('Copying control to: {0}'.format(imgpath))
shutil.copyfile(tmpimg, imgpath)
else:
raise OSError('Control not copied to: {0}'.format(imgpath))
开发者ID:GrokImageCompression,项目名称:QGIS,代码行数:44,代码来源:test_qgspallabeling_base.py
注:本文中的utilities.getTempfilePath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论