本文整理汇总了Python中loader.Loader.start方法的典型用法代码示例。如果您正苦于以下问题:Python Loader.start方法的具体用法?Python Loader.start怎么用?Python Loader.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类loader.Loader
的用法示例。
在下文中一共展示了Loader.start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpeedyLayer
# 需要导入模块: from loader import Loader [as 别名]
# 或者: from loader.Loader import start [as 别名]
#.........这里部分代码省略.........
icon_path = ':/plugins/SpeedyLayer/icon.png'
self.add_action(
icon_path,
text=self.tr(u'Speedy Layer'),
callback=self.run,
parent=self.iface.mainWindow())
#add contextual menu
self.dup_to_memory_layer_action = QAction(QIcon(icon_path), "Duplicate to memory layer", self.iface.legendInterface() )
self.iface.legendInterface().addLegendLayerAction(self.dup_to_memory_layer_action, "","01", QgsMapLayer.VectorLayer,True)
self.dup_to_memory_layer_action.triggered.connect(self.run)
def unload(self):
"""Removes the plugin menu item and icon from QGIS GUI."""
for action in self.actions:
self.iface.removePluginMenu(
self.tr(u'&Speedy Layer'),
action)
self.iface.removeToolBarIcon(action)
# remove the toolbar
del self.toolbar
# remove contextual menu
self.iface.legendInterface().removeLegendLayerAction(self.dup_to_memory_layer_action)
def process(self):
if len(self.allVectorLayers) > 0:
self.vectorLayer = self.allVectorLayers[self.dlg.cmbVectorLayer.currentIndex()]
self.memoryLayer = self.generateMemoryLayer(self.vectorLayer,self.selectedLayerFields)
self.loader = Loader(targetLayer=self.memoryLayer,sourceLayer=self.vectorLayer)
self.loader.setOptions(onlySelected=self.dlg.checkBox.isChecked())
self.dlg.btnStart.setEnabled(False)
self.dlg.btnStop.setEnabled(True)
self.dlg.btnStop.clicked.connect(self.loader.stop)
self.iface.mapCanvas().setRenderFlag(False)#QGIS can not render dramatic changes in the target layer feature count and crashes down. So before starting we need to stop rendering.
QObject.connect(self.loader, SIGNAL("progressLenght"), self.setProgressLength)
QObject.connect(self.loader, SIGNAL("progress"), self.setProgress)
QObject.connect(self.loader, SIGNAL("error"), self.error)
QObject.connect(self.loader, SIGNAL("finished()"), self.done)
QObject.connect(self.loader, SIGNAL('status'), self.setStatus)
# QObject.connect(self.loader, SIGNAL('debug'), self.debug)
self.loader.start()
else:
QMessageBox.warning(self.dlg, u'Error', u'There must be at least one vector layers added in QGIS canvas.')
# def debug(self,msg):
# QMessageBox.information(None,'debug',msg)
def setProgress(self, val):
self.dlg.progressBar.setValue(val)
def setProgressLength(self, val):
self.dlg.progressBar.setMaximum(val)
if val==0:
self.dlg.btnStop.setEnabled(False)#this control may prevent errors when clicking stop button during saving changes.
def error(self, exception):
QMessageBox.critical(self.dlg, 'Error', str(exception) + '. All changes were rollbacked.')
def done(self):
#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.
示例2: featureLoader
# 需要导入模块: from loader import Loader [as 别名]
# 或者: from loader.Loader import start [as 别名]
#.........这里部分代码省略.........
icon_path = ':/plugins/featureLoader/icon.png'
self.add_action(
icon_path,
text=self.tr(u'Feature Loader'),
callback=self.run,
parent=self.iface.mainWindow())
def unload(self):
"""Removes the plugin menu item and icon from QGIS GUI."""
for action in self.actions:
self.iface.removePluginMenu(
self.tr(u'&Feature Loader'),
action)
self.iface.removeToolBarIcon(action)
# remove the toolbar
del self.toolbar
def layerControl(self):
if len(self.allVectorLayers) > 1:
self.targetLayer = self.allVectorLayers[self.dlg.cmbTargetLayer.currentIndex()]
sourceLayer = self.allVectorLayers[self.dlg.cmbSourceLayer.currentIndex()]
openedAttrWindow = False #This variable is used for detecting opened attribute windows. During loading operation, opened windows make qgis crashed (maybe a bug)
#so they must be closed
for dialog in QApplication.instance().allWidgets():
#I noticed that in my laptop getting all Qt widget's (in QGIS) names give error. But no problem with desktop. Here is try-except ;)
try:
if dialog.objectName() in [u'QgsAttributeTableDialog', u'AttributeTable']:
openedAttrWindow = True
except:
pass
if openedAttrWindow:
QMessageBox.warning(None,u'Notification', u'Please close all attribute windows to start the process.')
else:
#checking target and source layers must not be in editing mode.
if not self.targetLayer.isEditable() and not sourceLayer.isEditable():
# checking for targetLayer editing capability.
isEditable = self.targetLayer.dataProvider().capabilities() & QgsVectorDataProvider.AddFeatures
if isEditable:
# checking targetLayer and sourceLayer are not same
if self.targetLayer.extent() != sourceLayer.extent() or self.targetLayer.publicSource() != sourceLayer.publicSource():
# checking layers geometry types
if self.targetLayer.geometryType() == sourceLayer.geometryType():
self.loader = Loader(targetLayer=self.targetLayer,sourceLayer=sourceLayer)
self.loader.setOptions(onlySelected=self.dlg.checkBox.isChecked())
self.dlg.btnStart.setEnabled(False)
self.dlg.btnStop.setEnabled(True)
self.dlg.btnStop.clicked.connect(self.loader.stop)
self.iface.mapCanvas().setRenderFlag(False)#QGIS can not render dramatic changes in the target layer feature count and crashes down. So before starting we need to stop rendering.
QObject.connect(self.loader, SIGNAL("progressLenght"), self.setProgressLength)
QObject.connect(self.loader, SIGNAL("progress"), self.setProgress)
QObject.connect(self.loader, SIGNAL("error"), self.error)
QObject.connect(self.loader, SIGNAL("finished()"), self.done)
QObject.connect(self.loader, SIGNAL('status'), self.setStatus)
# QObject.connect(self.loader, SIGNAL('insertFeature'), self.insert)
self.loader.start()
self.start_time = timeit.default_timer()#for calculating total run time
else:
QMessageBox.warning(self.dlg, u'Error',
u'The layers geometry types have to be same to start the process.')
else:
示例3:
# 需要导入模块: from loader import Loader [as 别名]
# 或者: from loader.Loader import start [as 别名]
# *-* coding:utf-8 *-*
from loader import Loader
if __name__ == '__main__':
Loader.load()
from gl import LOG
LOG.info('START[doit start]')
Loader.start()