本文整理汇总了Python中qgis.utils.unloadPlugin函数的典型用法代码示例。如果您正苦于以下问题:Python unloadPlugin函数的具体用法?Python unloadPlugin怎么用?Python unloadPlugin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unloadPlugin函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: installFromZipFile
def installFromZipFile(self, filePath):
if not os.path.isfile(filePath):
return
settings = QgsSettings()
settings.setValue(settingsGroup + '/lastZipDirectory',
QFileInfo(filePath).absoluteDir().absolutePath())
error = False
infoString = None
with zipfile.ZipFile(filePath, 'r') as zf:
pluginName = os.path.split(zf.namelist()[0])[0]
pluginFileName = os.path.splitext(os.path.basename(filePath))[0]
pluginsDirectory = qgis.utils.home_plugin_path
if not QDir(pluginsDirectory).exists():
QDir().mkpath(pluginsDirectory)
# If the target directory already exists as a link,
# remove the link without resolving
QFile(os.path.join(pluginsDirectory, pluginFileName)).remove()
try:
# Test extraction. If fails, then exception will be raised
# and no removing occurs
unzip(str(filePath), str(pluginsDirectory))
# Removing old plugin files if exist
removeDir(QDir.cleanPath(os.path.join(pluginsDirectory, pluginFileName)))
# Extract new files
unzip(str(filePath), str(pluginsDirectory))
except:
error = True
infoString = (self.tr("Plugin installation failed"),
self.tr("Failed to unzip the plugin package\n{}.\nProbably it is broken".format(filePath)))
if infoString is None:
updateAvailablePlugins()
loadPlugin(pluginName)
plugins.getAllInstalled(testLoad=True)
plugins.rebuild()
if settings.contains('/PythonPlugins/' + pluginName):
if settings.value('/PythonPlugins/' + pluginName, False, bool):
startPlugin(pluginName)
reloadPlugin(pluginName)
else:
unloadPlugin(pluginName)
loadPlugin(pluginName)
else:
if startPlugin(pluginName):
settings.setValue('/PythonPlugins/' + pluginName, True)
infoString = (self.tr("Plugin installed successfully"), "")
if infoString[0]:
level = error and QgsMessageBar.CRITICAL or QgsMessageBar.INFO
msg = "<b>%s:</b>%s" % (infoString[0], infoString[1])
iface.pluginManagerInterface().pushMessage(msg, level)
开发者ID:giohappy,项目名称:QGIS,代码行数:59,代码来源:installer.py
示例2: uninstallPlugin
def uninstallPlugin(self, key, quiet=False):
""" Uninstall given plugin """
if plugins.all().has_key(key):
plugin = plugins.all()[key]
else:
plugin = plugins.localCache[key]
if not plugin:
return
if not quiet:
warning = self.tr("Are you sure you want to uninstall the following plugin?") + "\n(" + plugin["name"] + ")"
if plugin["status"] == "orphan" and not plugin["error"]:
warning += "\n\n" + self.tr("Warning: this plugin isn't available in any accessible repository!")
if (
QMessageBox.warning(
iface.mainWindow(),
self.tr("QGIS Python Plugin Installer"),
warning,
QMessageBox.Yes,
QMessageBox.No,
)
== QMessageBox.No
):
return
# unload the plugin
try:
unloadPlugin(key)
except:
pass
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugin["id"]
result = removeDir(pluginDir)
if result:
QMessageBox.warning(iface.mainWindow(), self.tr("Plugin uninstall failed"), result)
else:
# safe remove
try:
unloadPlugin(plugin["id"])
except:
pass
try:
exec("plugins[%s].unload()" % plugin["id"])
exec("del plugins[%s]" % plugin["id"])
except:
pass
try:
exec("del sys.modules[%s]" % plugin["id"])
except:
pass
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
QMessageBox.information(
iface.mainWindow(),
self.tr("Plugin uninstalled successfully"),
self.tr("Plugin uninstalled successfully"),
)
开发者ID:jetuk,项目名称:Quantum-GIS,代码行数:55,代码来源:installer.py
示例3: uninstallPlugin
def uninstallPlugin(self, key, quiet=False):
""" Uninstall given plugin """
if key in plugins.all():
plugin = plugins.all()[key]
else:
plugin = plugins.localCache[key]
if not plugin:
return
if not quiet:
warning = self.tr("Are you sure you want to uninstall the following plugin?") + "\n(" + plugin["name"] + ")"
if plugin["status"] == "orphan" and not plugin["error"]:
warning += "\n\n" + self.tr("Warning: this plugin isn't available in any accessible repository!")
if (
QMessageBox.warning(
iface.mainWindow(),
self.tr("QGIS Python Plugin Installer"),
warning,
QMessageBox.Yes,
QMessageBox.No,
)
== QMessageBox.No
):
return
# unload the plugin
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
unloadPlugin(key)
except:
pass
pluginDir = qgis.utils.home_plugin_path + "/" + plugin["id"]
result = removeDir(pluginDir)
if result:
QApplication.restoreOverrideCursor()
msg = "<b>%s:</b>%s" % (self.tr("Plugin uninstall failed"), result)
iface.pluginManagerInterface().pushMessage(msg, QgsMessageBar.CRITICAL)
else:
# safe remove
try:
unloadPlugin(plugin["id"])
except:
pass
try:
exec("plugins[%s].unload()" % plugin["id"])
exec("del plugins[%s]" % plugin["id"])
except:
pass
try:
exec("del sys.modules[%s]" % plugin["id"])
except:
pass
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
QApplication.restoreOverrideCursor()
iface.pluginManagerInterface().pushMessage(self.tr("Plugin uninstalled successfully"), QgsMessageBar.INFO)
开发者ID:Zakui,项目名称:QGIS,代码行数:55,代码来源:installer.py
示例4: uninstallPlugin
def uninstallPlugin(self,key):
""" uninstall currently selected plugin """
plugin = plugins.all()[key]
if not plugin:
return
warning = self.tr("Are you sure you want to uninstall the following plugin?") + "\n(" + plugin["name"] + ")"
if plugin["status"] == "orphan" and not plugin["error"]:
warning += "\n\n"+self.tr("Warning: this plugin isn't available in any accessible repository!")
if QMessageBox.warning(self, self.tr("QGIS Python Plugin Installer"), warning , QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
return
# unload the plugin if it's not plugin_installer itself (otherwise, do it after removing its directory):
if key != "plugin_installer":
try:
unloadPlugin(key)
except:
pass
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugin["localdir"]
result = removeDir(pluginDir)
if result:
QMessageBox.warning(self, self.tr("Plugin uninstall failed"), result)
else:
# if the uninstalled plugin is the installer itself, reload it and quit
if key == "plugin_installer":
if QGIS_15:
try:
QMessageBox.information(self, self.tr("QGIS Python Plugin Installer"), self.tr("Plugin Installer update uninstalled. Plugin Installer will now close and revert to its primary version. You can find it in the Plugins menu and continue operation."))
reloadPlugin(key)
return
except:
pass
else:
QMessageBox.information(self, self.tr("QGIS Python Plugin Installer"), self.tr("Plugin Installer update uninstalled. Please restart QGIS in order to load its primary version."))
# safe remove
try:
unloadPlugin(plugin["localdir"])
except:
pass
try:
exec ("plugins[%s].unload()" % plugin["localdir"])
exec ("del plugins[%s]" % plugin["localdir"])
except:
pass
try:
exec ("del sys.modules[%s]" % plugin["localdir"])
except:
pass
plugins.getAllInstalled()
plugins.rebuild()
self.populatePluginTree()
if QGIS_14: QMessageBox.information(self, self.tr("Plugin uninstalled successfully"), self.tr("Plugin uninstalled successfully"))
else: QMessageBox.information(self, self.tr("Plugin uninstalled successfully"), self.tr("Python plugin uninstalled. Note that you may need to restart Quantum GIS in order to remove it completely."))
history.markChange(key,'D')
开发者ID:CzendaZdenda,项目名称:qgis,代码行数:52,代码来源:installer_gui.py
示例5: testInstallFromZip
def testInstallFromZip(self):
"""Test plugin installation from ZIP package"""
pluginPath = os.path.join(testPath, 'data', 'connecttest.zip')
result = utils.installFromZipFile(pluginPath)
self.assertIsNone(result), 'Error installing plugin: {}'.format(result)
self.assertTrue('connecttest' in qgsutils.active_plugins), 'Plugin not activated'
unloadPlugin('connecttest')
result = removeDir(os.path.join(home_plugin_path, 'connecttest'))
self.assertFalse(result, 'Plugin directory not removed')
result = utils.installFromZipFile(pluginPath)
self.assertIsNone(result), 'Error installing plugin: {}'.format(result)
self.assertTrue('connecttest' in qgsutils.active_plugins), 'Plugin not activated after reinstallation'
开发者ID:boundlessgeo,项目名称:qgis-connect-plugin,代码行数:13,代码来源:testerplugin.py
示例6: installFromZipFile
def installFromZipFile(pluginPath):
"""Install and activate plugin from the specified package
"""
result = None
with zipfile.ZipFile(pluginPath, 'r') as zf:
pluginName = os.path.split(zf.namelist()[0])[0]
pluginFileName = os.path.splitext(os.path.basename(pluginPath))[0]
pluginsDirectory = home_plugin_path
if not QDir(pluginsDirectory).exists():
QDir().mkpath(pluginsDirectory)
# If the target directory already exists as a link,
# remove the link without resolving
QFile(os.path.join(pluginsDirectory, pluginFileName)).remove()
try:
# Test extraction. If fails, then exception will be raised
# and no removing occurs
unzip(unicode(pluginPath), unicode(pluginsDirectory))
# Removing old plugin files if exist
removeDir(QDir.cleanPath(os.path.join(pluginsDirectory, pluginFileName)))
# Extract new files
unzip(unicode(pluginPath), unicode(pluginsDirectory))
except:
result = QCoreApplication.translate('BoundlessConnect',
'Failed to unzip the plugin package\n{}.\nProbably it is broken'.format(pluginPath))
if result is None:
updateAvailablePlugins()
loadPlugin(pluginName)
plugins.getAllInstalled(testLoad=True)
plugins.rebuild()
plugin = plugins.all()[pluginName]
settings = QSettings()
if settings.contains('/PythonPlugins/' + pluginName):
if settings.value('/PythonPlugins/' + pluginName, False, bool):
startPlugin(pluginName)
reloadPlugin(pluginName)
else:
unloadPlugin(pluginName)
loadPlugin(pluginName)
else:
if startPlugin(pluginName):
settings.setValue('/PythonPlugins/' + pluginName, True)
return result
开发者ID:elpaso,项目名称:qgis-connect-plugin,代码行数:50,代码来源:utils.py
示例7: applyPlugins
def applyPlugins(profile):
if profile.plugins is None:
return
toInstall = [p for p in profile.plugins if p not in utils.available_plugins]
pluginErrors = []
for p in toInstall:
error = installPlugin(p)
if error:
pluginErrors.append(error)
settings = QSettings()
ignore = list(pluginsToIgnore)
layers = QgsMapLayerRegistry.instance().mapLayers().values()
for lyr in layers:
if lyr.type() == QgsMapLayer.PluginLayer:
ignore.extend(pluginsWithLayers)
break
tounload = [p for p in utils.active_plugins if p not in ignore]
for p in tounload:
try:
unloadPlugin(p)
except:
pass
settings.setValue('/PythonPlugins/' + p, False)
updateAvailablePlugins()
for p in profile.plugins:
if p not in utils.active_plugins and p in utils.available_plugins:
loadPlugin(p)
startPlugin(p)
settings.setValue('/PythonPlugins/' + p, True)
updateAvailablePlugins()
updatePluginManager()
return pluginErrors
开发者ID:boundlessgeo,项目名称:qgis-profiles-plugin,代码行数:38,代码来源:utils.py
示例8: installPlugin
def installPlugin(self, key, quiet=False):
""" Install given plugin """
error = False
infoString = ('', '')
plugin = plugins.all()[key]
previousStatus = plugin["status"]
if not plugin:
return
if plugin["status"] == "newer" and not plugin["error"]: # ask for confirmation if user downgrades an usable plugin
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Are you sure you want to downgrade the plugin to the latest available version? The installed one is newer!"), QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
return
dlg = QgsPluginInstallerInstallingDialog(iface.mainWindow(), plugin)
dlg.exec_()
if dlg.result():
error = True
infoString = (self.tr("Plugin installation failed"), dlg.result())
elif not QDir(qgis.utils.home_plugin_path + "/" + key).exists():
error = True
infoString = (self.tr("Plugin has disappeared"), self.tr("The plugin seems to have been installed but I don't know where. Probably the plugin package contained a wrong named directory.\nPlease search the list of installed plugins. I'm nearly sure you'll find the plugin there, but I just can't determine which of them it is. It also means that I won't be able to determine if this plugin is installed and inform you about available updates. However the plugin may work. Please contact the plugin author and submit this issue."))
QApplication.setOverrideCursor(Qt.WaitCursor)
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
QApplication.restoreOverrideCursor()
else:
QApplication.setOverrideCursor(Qt.WaitCursor)
# update the list of plugins in plugin handling routines
updateAvailablePlugins()
# try to load the plugin
loadPlugin(plugin["id"])
plugins.getAllInstalled(testLoad=True)
plugins.rebuild()
plugin = plugins.all()[key]
if not plugin["error"]:
if previousStatus in ["not installed", "new"]:
infoString = (self.tr("Plugin installed successfully"), "")
if startPlugin(plugin["id"]):
settings = QSettings()
settings.setValue("/PythonPlugins/" + plugin["id"], True)
else:
settings = QSettings()
if settings.value("/PythonPlugins/" + key, False, type=bool): # plugin will be reloaded on the fly only if currently loaded
reloadPlugin(key) # unloadPlugin + loadPlugin + startPlugin
infoString = (self.tr("Plugin reinstalled successfully"), "")
else:
unloadPlugin(key) # Just for a case. Will exit quietly if really not loaded
loadPlugin(key)
infoString = (self.tr("Plugin reinstalled successfully"), self.tr("Python plugin reinstalled.\nYou need to restart QGIS in order to reload it."))
if quiet:
infoString = (None, None)
QApplication.restoreOverrideCursor()
else:
QApplication.restoreOverrideCursor()
if plugin["error"] == "incompatible":
message = self.tr("The plugin is not compatible with this version of QGIS. It's designed for QGIS versions:")
message += " <b>" + plugin["error_details"] + "</b>"
elif plugin["error"] == "dependent":
message = self.tr("The plugin depends on some components missing on your system. You need to install the following Python module in order to enable it:")
message += "<b> " + plugin["error_details"] + "</b>"
else:
message = self.tr("The plugin is broken. Python said:")
message += "<br><b>" + plugin["error_details"] + "</b>"
dlg = QgsPluginInstallerPluginErrorDialog(iface.mainWindow(), message)
dlg.exec_()
if dlg.result():
# revert installation
pluginDir = qgis.utils.home_plugin_path + "/" + plugin["id"]
result = removeDir(pluginDir)
if QDir(pluginDir).exists():
error = True
infoString = (self.tr("Plugin uninstall failed"), result)
try:
exec ("sys.path_importer_cache.clear()")
exec ("import %s" % plugin["id"])
exec ("reload (%s)" % plugin["id"])
except:
pass
else:
try:
exec ("del sys.modules[%s]" % plugin["id"])
except:
pass
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
if infoString[0]:
level = error and QgsMessageBar.CRITICAL or QgsMessageBar.INFO
msg = "<b>%s:</b>%s" % (infoString[0], infoString[1])
iface.pluginManagerInterface().pushMessage(msg, level)
开发者ID:fritsvanveen,项目名称:QGIS,代码行数:93,代码来源:installer.py
示例9: installFromZipFile
def installFromZipFile(self, filePath):
if not os.path.isfile(filePath):
return
settings = QgsSettings()
settings.setValue(settingsGroup + '/lastZipDirectory',
QFileInfo(filePath).absoluteDir().absolutePath())
with zipfile.ZipFile(filePath, 'r') as zf:
pluginName = os.path.split(zf.namelist()[0])[0]
pluginFileName = os.path.splitext(os.path.basename(filePath))[0]
pluginsDirectory = qgis.utils.home_plugin_path
if not QDir(pluginsDirectory).exists():
QDir().mkpath(pluginsDirectory)
pluginDirectory = QDir.cleanPath(os.path.join(pluginsDirectory, pluginName))
# If the target directory already exists as a link,
# remove the link without resolving
QFile(pluginDirectory).remove()
password = None
infoString = None
success = False
keepTrying = True
while keepTrying:
try:
# Test extraction. If fails, then exception will be raised and no removing occurs
unzip(filePath, pluginsDirectory, password)
# Removing old plugin files if exist
removeDir(pluginDirectory)
# Extract new files
unzip(filePath, pluginsDirectory, password)
keepTrying = False
success = True
except Exception as e:
success = False
if 'password' in str(e):
infoString = self.tr('Aborted by user')
if 'Bad password' in str(e):
msg = self.tr('Wrong password. Please enter a correct password to the zip file.')
else:
msg = self.tr('The zip file is encrypted. Please enter password.')
# Display a password dialog with QgsPasswordLineEdit
dlg = QDialog()
dlg.setWindowTitle(self.tr('Enter password'))
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal)
buttonBox.rejected.connect(dlg.reject)
buttonBox.accepted.connect(dlg.accept)
lePass = QgsPasswordLineEdit()
layout = QVBoxLayout()
layout.addWidget(QLabel(msg))
layout.addWidget(lePass)
layout.addWidget(buttonBox)
dlg.setLayout(layout)
keepTrying = dlg.exec_()
password = lePass.text()
else:
infoString = self.tr("Failed to unzip the plugin package\n{}.\nProbably it is broken".format(filePath))
keepTrying = False
if success:
updateAvailablePlugins()
loadPlugin(pluginName)
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
if settings.contains('/PythonPlugins/' + pluginName):
if settings.value('/PythonPlugins/' + pluginName, False, bool):
startPlugin(pluginName)
reloadPlugin(pluginName)
else:
unloadPlugin(pluginName)
loadPlugin(pluginName)
else:
if startPlugin(pluginName):
settings.setValue('/PythonPlugins/' + pluginName, True)
msg = "<b>%s</b>" % self.tr("Plugin installed successfully")
else:
msg = "<b>%s:</b> %s" % (self.tr("Plugin installation failed"), infoString)
level = Qgis.Info if success else Qgis.Critical
iface.pluginManagerInterface().pushMessage(msg, level)
开发者ID:anitagraser,项目名称:QGIS,代码行数:88,代码来源:installer.py
示例10: _removeTestPlugin
def _removeTestPlugin():
unloadPlugin("what3words")
updateAvailablePlugins()
updatePluginManager()
assert "what3words" not in available_plugins
开发者ID:boundlessgeo,项目名称:qgis-profiles-plugin,代码行数:5,代码来源:testerplugin.py
注:本文中的qgis.utils.unloadPlugin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论