本文整理汇总了Python中qgis.core.QgsTask.fromFunction方法的典型用法代码示例。如果您正苦于以下问题:Python QgsTask.fromFunction方法的具体用法?Python QgsTask.fromFunction怎么用?Python QgsTask.fromFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsTask
的用法示例。
在下文中一共展示了QgsTask.fromFunction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testTaskFromFunctionWithFlags
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionWithFlags(self):
""" test creating task from function with flags"""
task = QgsTask.fromFunction('test task', run, 20, flags=QgsTask.Flags())
self.assertFalse(task.canCancel())
task2 = QgsTask.fromFunction('test task', run, 20, flags=QgsTask.CanCancel)
self.assertTrue(task2.canCancel())
示例2: testTaskFromFunctionWithSubTaskCompletedIsCalledOnce
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionWithSubTaskCompletedIsCalledOnce(self): # spellok
""" test that when a parent task has subtasks it does emit taskCompleted only once"""
self.finished = 0
self.completed = 0
def _on_finished(e):
self.finished += 1
def _on_completed():
self.completed += 1
task = QgsTask.fromFunction('test task', run_no_result, on_finished=_on_finished)
task.taskCompleted.connect(_on_completed)
spy = QSignalSpy(task.taskCompleted)
sub_task_1 = QgsTask.fromFunction('test subtask 1', run_no_result, on_finished=_on_finished)
sub_task_2 = QgsTask.fromFunction('test subtask 2', run_no_result, on_finished=_on_finished)
task.addSubTask(sub_task_1, [], QgsTask.ParentDependsOnSubTask)
task.addSubTask(sub_task_2, [], QgsTask.ParentDependsOnSubTask)
QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
QCoreApplication.processEvents()
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()
self.assertEqual(self.completed, 1)
self.assertEqual(self.finished, 3)
self.assertEqual(len(spy), 1)
示例3: testTaskFromFunctionWithKwargs
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionWithKwargs(self):
""" test creating task from function using kwargs """
task = QgsTask.fromFunction('test task3', run_with_kwargs, result=5, password=1)
QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
self.assertEqual(task.returned_values, 5)
self.assertFalse(task.exception)
self.assertEqual(task.status(), QgsTask.Complete)
示例4: testTaskFromFunction
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunction(self):
""" test creating task from function """
task = QgsTask.fromFunction('test task', run, 20)
QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
self.assertEqual(task.returned_values, 20)
self.assertFalse(task.exception)
self.assertEqual(task.status(), QgsTask.Complete)
# try a task which cancels itself
bad_task = QgsTask.fromFunction('test task2', run, None)
QgsApplication.taskManager().addTask(bad_task)
while bad_task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
self.assertFalse(bad_task.returned_values)
self.assertTrue(bad_task.exception)
self.assertEqual(bad_task.status(), QgsTask.Terminated)
示例5: testTaskFromFunctionFinishedWithVal
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionFinishedWithVal(self):
""" test that task from function can have callback finished function and is passed result values"""
task = QgsTask.fromFunction('test task', run_single_val_result, on_finished=finished_single_value_result)
QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()
# check that the finished function was called
self.assertEqual(task.returned_values, (5))
self.assertFalse(task.exception)
self.assertEqual(finished_single_value_result.value, 5)
示例6: testTaskFromFunctionFinishedFail
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionFinishedFail(self):
""" test that task from function which fails calls finished with exception"""
task = QgsTask.fromFunction('test task', run_fail, on_finished=finished_fail)
QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()
# check that the finished function was called
self.assertTrue(task.exception)
self.assertTrue(finished_fail.finished_exception)
self.assertEqual(task.exception, finished_fail.finished_exception)
示例7: testTaskFromFunctionFinished
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionFinished(self):
""" test that task from function can have callback finished function"""
task = QgsTask.fromFunction('test task', run_no_result, on_finished=finished_no_val)
QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()
# check that the finished function was called
self.assertFalse(task.returned_values)
self.assertFalse(task.exception)
self.assertTrue(finished_no_val.called)
示例8: testTaskFromFunctionCanceledWhileQueued
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionCanceledWhileQueued(self):
""" test that task from finished is called with exception when task is terminated while queued"""
task = QgsTask.fromFunction('test task', run_no_result, on_finished=finished_fail)
task.hold()
QgsApplication.taskManager().addTask(task)
task.cancel()
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()
# check that the finished function was called
self.assertTrue(task.exception)
self.assertTrue(finished_fail.finished_exception)
self.assertEqual(task.exception, finished_fail.finished_exception)
示例9: testTaskFromFunctionIsCancellable
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionIsCancellable(self):
""" test that task from function can check canceled status """
bad_task = QgsTask.fromFunction('test task4', cancellable)
QgsApplication.taskManager().addTask(bad_task)
while bad_task.status() != QgsTask.Running:
pass
bad_task.cancel()
while bad_task.status() == QgsTask.Running:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()
self.assertEqual(bad_task.status(), QgsTask.Terminated)
self.assertTrue(bad_task.exception)
示例10: testTaskFromFunctionCanSetProgress
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionCanSetProgress(self):
""" test that task from function can set progress """
task = QgsTask.fromFunction('test task5', progress_function)
QgsApplication.taskManager().addTask(task)
while task.status() != QgsTask.Running:
pass
# wait a fraction so that setProgress gets a chance to be called
sleep(0.001)
self.assertEqual(task.progress(), 50)
self.assertFalse(task.exception)
task.cancel()
while task.status() == QgsTask.Running:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()
示例11: runTask
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def runTask(self, dataRun):
def finished(exception, dataResult):
def endEditable():
self.layerPolygon.commitChanges()
self.layerPolygon.updateExtents()
if self.isIniEditable:
self.layerPolygon.startEditing()
def setRenderLayer():
fileStyle = os.path.join( os.path.dirname( __file__ ), "gimpselectionfeature_with_expression.qml" )
self.layerPolygon.loadNamedStyle( fileStyle )
self.mapCanvasEffects.zoom( self.layerPolygon, dataResult['geomBBox'] )
self.msgBar.clearWidgets()
if exception:
self.msgBar.pushMessage( self.nameModulus, str( exception ), Qgis.Critical )
return
self.msgBar.pushMessage( self.nameModulus, dataResult['message'], dataResult['level'] )
if 'getFeatures' == dataResult['process']:
endEditable()
imgs = filter( lambda f: os.path.exists( f ), ( self.pathfileImage, self.pathfileImageSelect ) )
[ os.remove( item ) for item in imgs ]
if dataResult['isOk']:
setRenderLayer()
self.setEnabledWidgetTransfer( True, True )
else:
self.setEnabledWidgetTransfer( True )
else:
self.setEnabledWidgetTransfer( True )
def run(task, data):
self.worker.setData( task, data )
return self.worker.run()
self.setEnabledWidgetTransfer( False )
task = QgsTask.fromFunction('GimpSelectionFeature Task', run, dataRun, on_finished=finished )
if not self.layerPolygon is None:
task.setDependentLayers( [ self.layerPolygon ] )
self.taskManager.addTask( task )
示例12: testTaskFromFunctionFinishedWithMultipleValues
# 需要导入模块: from qgis.core import QgsTask [as 别名]
# 或者: from qgis.core.QgsTask import fromFunction [as 别名]
def testTaskFromFunctionFinishedWithMultipleValues(self):
""" test that task from function can have callback finished function and is passed multiple result values"""
result_value = None
result_statement = None
def finished_multiple_value_result(e, results):
nonlocal result_value
nonlocal result_statement
assert e is None
result_value = results[0]
result_statement = results[1]
task = QgsTask.fromFunction('test task', run_multiple_val_result, on_finished=finished_multiple_value_result)
QgsApplication.taskManager().addTask(task)
while task.status() not in [QgsTask.Complete, QgsTask.Terminated]:
pass
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()
# check that the finished function was called
self.assertEqual(task.returned_values, (5, 'whoo'))
self.assertFalse(task.exception)
self.assertEqual(result_value, 5)
self.assertEqual(result_statement, 'whoo')