Navigation Menu

Skip to content

Commit

Permalink
Look for and load plugins from the users .qgis directory.
Browse files Browse the repository at this point in the history
Patch from Matthew Perry, ticket #781


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7282 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
gsherman committed Oct 22, 2007
1 parent 809577f commit 2279ebb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
14 changes: 6 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -1563,14 +1563,13 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
if (QgsPythonUtils::isEnabled())
{

// check for python plugins
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);

for (uint i = 0; i < pluginDir.count(); i++)
// check for python plugins system-wide
QStringList pluginList = QgsPythonUtils::pluginList();

for (int i = 0; i < pluginList.size(); i++)
{
QString packageName = pluginDir[i];
QString packageName = pluginList[i];

// import plugin's package
if (!QgsPythonUtils::loadPlugin(packageName))
continue;
Expand All @@ -1596,7 +1595,6 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
loadPythonPlugin(packageName, pluginName);
}
}

}
#endif
}
Expand Down
14 changes: 6 additions & 8 deletions src/app/qgspluginmanager.cpp
Expand Up @@ -83,14 +83,13 @@ void QgsPluginManager::getPythonPluginDescriptions()
if (!QgsPythonUtils::isEnabled())
return;

// look for plugins
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);

for (uint i = 0; i < pluginDir.count(); i++)
// look for plugins systemwide
QStringList pluginList = QgsPythonUtils::pluginList();

for (int i = 0; i < pluginList.size(); i++)
{
QString packageName = pluginDir[i];
QString packageName = pluginList[i];

// import plugin's package
QgsPythonUtils::loadPlugin(packageName);

Expand Down Expand Up @@ -125,7 +124,6 @@ void QgsPluginManager::getPythonPluginDescriptions()
pl->setOn(true);
}
}

}
#endif
}
Expand Down
31 changes: 29 additions & 2 deletions src/app/qgspythonutils.cpp
Expand Up @@ -24,7 +24,8 @@
#include "qgslogger.h"

#include <QMessageBox>

#include <QStringList>
#include <QDir>

QString QgsPythonUtils::mPluginsPath;
PyObject* QgsPythonUtils::mMainModule;
Expand All @@ -47,7 +48,7 @@ void QgsPythonUtils::initPython(QgisInterface* interface)

// expect that bindings are installed locally, so add the path to modules
// also add path to plugins
runString("sys.path = [\"" + pythonPath() + "\", \"" + pluginsPath() + "\"] + sys.path");
runString("sys.path = [\"" + homePluginsPath() + "\", \"" + pythonPath() + "\", \"" + pluginsPath() + "\"] + sys.path");

// import SIP
if (!runString("from sip import wrapinstance, unwrapinstance"))
Expand Down Expand Up @@ -284,6 +285,32 @@ QString QgsPythonUtils::pluginsPath()
return pythonPath() + "/plugins";
}

QString QgsPythonUtils::homePluginsPath()
{
return QgsApplication::qgisSettingsDirPath() + "/python/plugins/";
}

QStringList QgsPythonUtils::pluginList()
{
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);

QDir homePluginDir(QgsPythonUtils::homePluginsPath(), "*",
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);

QStringList pluginList = pluginDir.entryList();

for (uint i = 0; i < homePluginDir.count(); i++)
{
QString packageName = homePluginDir[i];
if(!pluginList.contains(packageName))
pluginList.append(packageName);

}

return pluginList;
}

QString QgsPythonUtils::getPluginMetadata(QString pluginName, QString function)
{
QString command = pluginName + "." + function + "()";
Expand Down
9 changes: 8 additions & 1 deletion src/app/qgspythonutils.h
Expand Up @@ -15,6 +15,7 @@
/* $Id$ */

#include <QString>
#include <QStringList>

// forward declaration for PyObject
#ifndef PyObject_HEAD
Expand Down Expand Up @@ -84,7 +85,13 @@ class QgsPythonUtils

//! return current path for python plugins
static QString pluginsPath();


//! return current path for home directory python plugins
static QString homePluginsPath();

//! return list of all available python plugins
static QStringList pluginList();

//! load python plugin (import)
static bool loadPlugin(QString packageName);

Expand Down

0 comments on commit 2279ebb

Please sign in to comment.