if I try to load the openlayers plugin in a standalone application it always fails with False, although paths are set, and plugin shows available.
(tested on Ubuntu 14.04, QGIS 2.4, python-2.7)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, os
import qgis
import qgis.gui, qgis.utils
from qgis.core import *
from PyQt4 import QtGui
# open an app
app = QtGui.QApplication(sys.argv)
# supply path to where is your qgis installed
QgsApplication.setPrefixPath(u'/usr', True)
# load providers
QgsApplication.initQgis()
# set up the plugins
qgis.utils.plugin_paths = \
['/usr/share/qgis/python/plugins',
os.path.expanduser('~/.qgis2/python/plugins'),]
qgis.utils.updateAvailablePlugins()
print qgis.utils.available_plugins
print "...load:", qgis.utils.loadPlugin(u'openlayers_plugin')
print "...start:", qgis.utils.startPlugin(u'openlayers_plugin')
print "active:\n",qgis.utils.active_plugins
canvas = qgis.gui.QgsMapCanvas()
canvas.show()
what is the issue here ? post How to fetch openlayers layers from pyqgis? refers to the embedded python console, where the plugin was magically available before.
thanks!
Answer
This is never, well maybe with some hacks, going to work well. Plugins normally use the QgisInterface
object which gives access to the QGIS interface and methods. You don't have this object in your standalone script. Most plugins, if not all, are not designed to run outside of QGIS like this.
No comments:
Post a Comment