本文整理匯總了Python中algorithm.Algorithm.moveToThread方法的典型用法代碼示例。如果您正苦於以下問題:Python Algorithm.moveToThread方法的具體用法?Python Algorithm.moveToThread怎麽用?Python Algorithm.moveToThread使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類algorithm.Algorithm
的用法示例。
在下文中一共展示了Algorithm.moveToThread方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: OutputTabManager
# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import moveToThread [as 別名]
#.........這裏部分代碼省略.........
iface.messageBar().pushCritical('QTraffic', message)
return
# load the layer
newLayerName =os.path.splitext(os.path.basename( newOutputLayer ))[0]
self.outLayer = QgsVectorLayer(newOutputLayer, newLayerName, 'ogr')
if not self.outLayer.isValid():
message = self.tr('Error loading vector file {}'.format(newOutputLayer))
QgsMessageLog.logMessage(message, 'QTraffic', QgsMessageLog.CRITICAL)
iface.messageBar().pushCritical('QTraffic', message)
return
self.outLayerId = self.outLayer.id()
# prepare environment
try:
self.alg.setProject(self.project)
self.alg.setLayer( roadLayer )
self.alg.initConfig()
self.alg.prepareRun()
except Exception as ex:
traceback.print_exc()
message = self.tr('Error preparing running contex for the algoritm: %s' % str(ex))
QgsMessageLog.logMessage(message, 'QTraffic', QgsMessageLog.CRITICAL)
iface.messageBar().pushCritical('QTraffic', message)
return
# run the self.alg
self.thread = QtCore.QThread(self)
self.thread.started.connect(self.alg.run)
self.thread.finished.connect(self.threadCleanup)
self.thread.terminated.connect(self.threadCleanup)
self.alg.moveToThread(self.thread)
self.alg.started.connect(self.manageStarted)
self.alg.progress.connect(self.manageProgress)
self.alg.message.connect(self.manageMessage)
self.alg.error.connect(self.manageError)
self.alg.finished.connect(self.manageFinished)
# set wait cursor and start
QgsApplication.instance().setOverrideCursor(QtCore.Qt.WaitCursor)
self.thread.start()
def checkOutLayerRemoved(self, layerId):
''' check when outLayer has been removed settign semaphore to True
'''
if self.outLayerId == layerId:
QgsMessageLog.logMessage('Completly removed outLayer', 'QTraffic', QgsMessageLog.INFO)
self.outLayerRemoved = True
def threadCleanup(self):
''' cleanup after thread run
'''
# restore cursor
QgsApplication.instance().restoreOverrideCursor()
if self.alg:
self.alg.deleteLater()
self.alg = None
self.thread.wait()
self.thread.deleteLater()
# remove progress bar
if self.progressMessageBarItem:
iface.messageBar().popWidget(self.progressMessageBarItem)