本文整理汇总了Python中loader.Loader.terminate方法的典型用法代码示例。如果您正苦于以下问题:Python Loader.terminate方法的具体用法?Python Loader.terminate怎么用?Python Loader.terminate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类loader.Loader
的用法示例。
在下文中一共展示了Loader.terminate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: featureLoader
# 需要导入模块: from loader import Loader [as 别名]
# 或者: from loader.Loader import terminate [as 别名]
#.........这里部分代码省略.........
# def insert(self,feat):
# self.targetLayer.startEditing()
# self.targetLayer.addFeature(feat)
def done(self):
#this function is used by loader class's finished() signal.
if not self.loader.hasError:
if not self.loader.isCancel:
# self.dlg.lblStatus
self.committer = Committer(self.targetLayer)#this thread saves changes to datasource.
QObject.connect(self.committer, SIGNAL("finished()"), lambda: self.commitFinished(self.targetLayer))
self.targetLayer.startEditing()
self.targetLayer.addFeatures(self.loader.featureList, False)
self.dlg.btnStop.setEnabled(False)
QObject.connect(self.committer, SIGNAL('commitStarted'), self.commitStarted)
self.committer.start()
# self.resultGenerator(targetLayer.commitErrors())
else:
self.resultGenerator(['Operation was canceled by user. All changes were rollbacked.'])
self.onStop()
else:
self.onStop()
def commitStarted(self):
self.dlg.lblStatus.setText(u'Please wait while saving changes to the datasource...')
self.dlg.progressBar.setMaximum(0)
self.dlg.btnStop.setEnabled(False)
def commitFinished(self,targetLayer):
self.onStop()
self.resultGenerator(targetLayer.commitErrors())
def error(self, exception):
QMessageBox.critical(self.dlg, 'Error', str(exception) + ' All changes were rollbacked.')
def onStop(self):
self.dlg.progressBar.reset()
self.dlg.progressBar.setMaximum(1)
self.dlg.lblStatus.clear()
self.loader.terminate()
try:
del self.loader
del self.committer
except:
pass
self.dlg.btnStart.setEnabled(True)
self.dlg.btnStop.setEnabled(False)
self.iface.mapCanvas().setRenderFlag(True)
self.iface.mapCanvas().refresh()
def resultGenerator(self, commitErrorList):
self.resultDlg.textEdit.clear()
total_run_time = '<p></p><b>Total execution time is %.2f seconds.</b><p></p>' % (timeit.default_timer()-self.start_time)
self.resultDlg.textEdit.append(total_run_time) #First line is total tun time information
for errorString in commitErrorList:
self.resultDlg.textEdit.append(errorString)
self.resultDlg.exec_()
def setStatus(self,message):
self.dlg.lblStatus.setText(message)
def run(self):
self.dlg = featureLoaderDialog()
self.resultDlg = resultDialog()
self.resultDlg.setFixedSize(self.resultDlg.size())
self.dlg.setFixedSize(self.dlg.size())
self.allVectorLayers = []
self.allMapLayers = QgsMapLayerRegistry.instance().mapLayers().items()
for (notImportantForNow, layerObj) in self.allMapLayers:
if layerObj.type() == 0:#0 is vectorlayer
self.allVectorLayers.append(layerObj)
if self.wkbText.has_key(layerObj.wkbType()):#Sometime qgis cannot return geometry type truly. This bug is handling in here
cmbLabel = layerObj.name() + ' (%d) (%s)' % (layerObj.featureCount(), self.wkbText[layerObj.wkbType()])
else:
cmbLabel = layerObj.name() + ' (%d) (%s)' % (layerObj.featureCount(), self.geometryText[layerObj.geometryType()])
self.dlg.cmbTargetLayer.addItem(cmbLabel)
self.dlg.cmbSourceLayer.addItem(cmbLabel)
self.dlg.btnStart.clicked.connect(self.layerControl)
# if len(self.allVectorLayers) < 2:
# self.dlg.btnStart.setEnabled(False)
result = self.dlg.exec_()
# Closing control
if not result:
try:
self.loader.stop()
self.committer.terminate()
del self.loader
del self.committer
except:
pass
示例2: SpeedyLayer
# 需要导入模块: from loader import Loader [as 别名]
# 或者: from loader.Loader import terminate [as 别名]
#.........这里部分代码省略.........
#this function is used by loader class's finished() signal.
if not self.loader.hasError:
if not self.loader.isCancel:
QgsMapLayerRegistry.instance().addMapLayer(self.memoryLayer)
self.committer = Committer(self.memoryLayer)#this thread saves changes to datasource.
QObject.connect(self.committer, SIGNAL("finished()"), self.commitFinished)
QObject.connect(self.committer, SIGNAL('commitStarted'), self.commitStarted)
self.memoryLayer.startEditing()
self.dlg.btnStop.setEnabled(False)
self.memoryLayer.addFeatures(self.loader.featureList, False)
self.committer.start()
else:
QMessageBox.information(self.dlg,'Result','Operation was canceled by user')
self.onStop()
else:
self.onStop()
def commitStarted(self):
self.dlg.lblStatus.setText(u'Please wait while memory allocation for new features...')
self.dlg.progressBar.setMaximum(0)
self.dlg.btnStop.setEnabled(False)
def commitFinished(self):
self.onStop()
QMessageBox.information(self.dlg,'Result', "Selected layer was copied to memory and added to the Canvas")
self.dlg.hide()
def onStop(self):
self.dlg.progressBar.setMaximum(1)
self.dlg.progressBar.reset()
self.dlg.lblStatus.clear()
self.loader.terminate()
try:
del self.loader
del self.committer
except:
pass
self.dlg.btnStart.setEnabled(True)
self.dlg.btnStop.setEnabled(False)
self.iface.mapCanvas().setRenderFlag(True)
self.iface.mapCanvas().refresh()
def setStatus(self,message):
self.dlg.lblStatus.setText(message)
def generateMemoryLayer(self, targetLayer, fieldDict):
epsg = 'EPSG:'+ str(targetLayer.crs().postgisSrid())
if self.geometryText.has_key(targetLayer.wkbType()):
geometry = self.wkbText[targetLayer.wkbType()]
else:
geometry = self.geometryText[targetLayer.geometryType()]
name = targetLayer.name()
memoryLayer = QgsVectorLayer(geometry + '?crs=' + epsg, name, "memory")
memoryLayer.startEditing()#to add field it needs to be in editing mode
for fieldName in fieldDict:
field = QgsField(fieldName, fieldDict[fieldName])
memoryLayer.dataProvider().addAttributes([field])
memoryLayer.updateFields()
memoryLayer.commitChanges()
return memoryLayer
def listFields(self):
#this function fills field comboboxes
self.selectedLayerFields = OrderedDict() #holds fieldname:type of all fields in selected layer