本文整理汇总了Python中processing.core.SilentProgress.SilentProgress类的典型用法代码示例。如果您正苦于以下问题:Python SilentProgress类的具体用法?Python SilentProgress怎么用?Python SilentProgress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SilentProgress类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runGdal
def runGdal(commands, progress=None):
if progress is None:
progress = SilentProgress()
envval = os.getenv("PATH")
# We need to give some extra hints to get things picked up on OS X
isDarwin = False
try:
isDarwin = platform.system() == "Darwin"
except IOError: # https://travis-ci.org/m-kuhn/QGIS#L1493-L1526
pass
if isDarwin and os.path.isfile(os.path.join(QgsApplication.prefixPath(), "bin", "gdalinfo")):
# Looks like there's a bundled gdal. Let's use it.
os.environ["PATH"] = "{}{}{}".format(os.path.join(QgsApplication.prefixPath(), "bin"), os.pathsep, envval)
os.environ["DYLD_LIBRARY_PATH"] = os.path.join(QgsApplication.prefixPath(), "lib")
else:
# Other platforms should use default gdal finder codepath
settings = QSettings()
path = settings.value("/GdalTools/gdalPath", "")
if not path.lower() in envval.lower().split(os.pathsep):
envval += "{}{}".format(os.pathsep, path)
os.putenv("PATH", envval)
fused_command = " ".join([str(c) for c in commands])
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, fused_command)
progress.setInfo("GDAL command:")
progress.setCommand(fused_command)
progress.setInfo("GDAL command output:")
success = False
retry_count = 0
while success == False:
loglines = []
loglines.append("GDAL execution console output")
try:
with subprocess.Popen(
fused_command,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
universal_newlines=True,
) as proc:
for line in proc.stdout:
progress.setConsoleInfo(line)
loglines.append(line)
success = True
except IOError as e:
if retry_count < 5:
retry_count += 1
else:
raise IOError(
e.message
+ u"\nTried 5 times without success. Last iteration stopped after reading {} line(s).\nLast line(s):\n{}".format(
len(loglines), u"\n".join(loglines[-10:])
)
)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
GdalUtils.consoleOutput = loglines
示例2: runalg
def runalg(alg, progress=None):
"""Executes a given algorithm, showing its progress in the
progress object passed along.
Return true if everything went OK, false if the algorithm
could not be completed.
"""
if progress is None:
progress = SilentProgress()
try:
alg.execute(progress)
return True
except GeoAlgorithmExecutionException as e:
ProcessingLog.addToLog(sys.exc_info()[0], ProcessingLog.LOG_ERROR)
progress.error(e.msg)
return False
示例3: runGdal
def runGdal(commands, progress=None):
if progress is None:
progress = SilentProgress()
envval = os.getenv('PATH')
# We need to give some extra hints to get things picked up on OS X
isDarwin = False
try:
isDarwin = platform.system() == 'Darwin'
except IOError: # https://travis-ci.org/m-kuhn/QGIS#L1493-L1526
pass
if isDarwin and os.path.isfile(os.path.join(QgsApplication.prefixPath(), "bin", "gdalinfo")):
# Looks like there's a bundled gdal. Let's use it.
os.environ['PATH'] = "{}{}{}".format(os.path.join(QgsApplication.prefixPath(), "bin"), os.pathsep, envval)
os.environ['DYLD_LIBRARY_PATH'] = os.path.join(QgsApplication.prefixPath(), "lib")
else:
# Other platforms should use default gdal finder codepath
settings = QSettings()
path = settings.value('/GdalTools/gdalPath', '')
if not path.lower() in envval.lower().split(os.pathsep):
envval += '{}{}'.format(os.pathsep, path)
os.putenv('PATH', envval)
loglines = []
loglines.append('GDAL execution console output')
fused_command = ''.join(['%s ' % c for c in commands])
progress.setInfo('GDAL command:')
progress.setCommand(fused_command)
proc = subprocess.Popen(
fused_command,
shell=True,
stdout=subprocess.PIPE,
stdin=open(os.devnull),
stderr=subprocess.STDOUT,
universal_newlines=True,
).stdout
progress.setInfo('GDAL command output:')
for line in iter(proc.readline, ''):
progress.setConsoleInfo(line)
loglines.append(line)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
GdalUtils.consoleOutput = loglines
示例4: handleAlgorithmResults
def handleAlgorithmResults(alg, progress=None, showResults=True):
wrongLayers = []
htmlResults = False
if progress is None:
progress = SilentProgress()
progress.setText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers'))
i = 0
for out in alg.outputs:
progress.setPercentage(100 * i / float(len(alg.outputs)))
if out.hidden or not out.open:
continue
if isinstance(out, (OutputRaster, OutputVector, OutputTable)):
try:
if hasattr(out, "layer") and out.layer is not None:
out.layer.setLayerName(out.description)
QgsMapLayerRegistry.instance().addMapLayers([out.layer])
else:
if ProcessingConfig.getSetting(
ProcessingConfig.USE_FILENAME_AS_LAYER_NAME):
name = os.path.basename(out.value)
else:
name = out.description
isRaster = True if isinstance(out, OutputRaster) else False
dataobjects.load(out.value, name, alg.crs,
RenderingStyles.getStyle(alg.commandLineName(), out.name),
isRaster)
except Exception:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
"Error loading result layer:\n" + traceback.format_exc())
wrongLayers.append(out.description)
elif isinstance(out, OutputHTML):
ProcessingResults.addResult(out.description, out.value)
htmlResults = True
i += 1
QApplication.restoreOverrideCursor()
if wrongLayers:
msg = "The following layers were not correctly generated.<ul>"
msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>"
msg += "You can check the log messages to find more information about the execution of the algorithm"
progress.error(msg)
if showResults and htmlResults and not wrongLayers:
dlg = ResultsDialog()
dlg.exec_()
return len(wrongLayers) == 0
示例5: runAlgorithm
def runAlgorithm(algOrName, onFinish, *args):
if isinstance(algOrName, GeoAlgorithm):
alg = algOrName
else:
alg = Processing.getAlgorithm(algOrName)
if alg is None:
print 'Error: Algorithm not found\n'
return
if len(args) != alg.getVisibleParametersCount() \
+ alg.getVisibleOutputsCount():
print 'Error: Wrong number of parameters'
processing.alghelp(algOrName)
return
alg = alg.getCopy()
if isinstance(args, dict):
# Set params by name
for (name, value) in args.items():
if alg.getParameterFromName(name).setValue(value):
continue
if alg.getOutputFromName(name).setValue(value):
continue
print 'Error: Wrong parameter value %s for parameter %s.' \
% (value, name)
return
else:
i = 0
for param in alg.parameters:
if not param.hidden:
if not param.setValue(args[i]):
print 'Error: Wrong parameter value: ' \
+ unicode(args[i])
return
i = i + 1
for output in alg.outputs:
if not output.hidden:
if not output.setValue(args[i]):
print 'Error: Wrong output value: ' + unicode(args[i])
return
i = i + 1
msg = alg.checkParameterValuesBeforeExecuting()
if msg:
print 'Unable to execute algorithm\n' + msg
return
if not alg.checkInputCRS():
print 'Warning: Not all input layers use the same CRS.\n' \
+ 'This can cause unexpected results.'
ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM, alg.getAsCommand())
# Don't set the wait cursor twice, because then when you
# restore it, it will still be a wait cursor.
cursor = QApplication.overrideCursor()
if cursor is None or cursor == 0:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
elif cursor.shape() != Qt.WaitCursor:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
progress = SilentProgress()
if interface.iface is not None :
progress = MessageBarProgress()
ret = UnthreadedAlgorithmExecutor.runalg(alg, progress)
if onFinish is not None and ret:
onFinish(alg, progress)
QApplication.restoreOverrideCursor()
progress.close()
return alg