Skip to content
Permalink
Browse files
[FEATURE] include ~/.qgis/python and project directory in python path
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12239 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 24, 2009
1 parent 9126b2b commit c608c0f2bbea50650db4d4d4f659e551cb14a8b2
Showing with 51 additions and 5 deletions.
  1. +36 −3 src/app/qgisapp.cpp
  2. +5 −0 src/app/qgisapp.h
  3. +7 −2 src/python/qgspythonutilsimpl.cpp
  4. +3 −0 src/python/qgspythonutilsimpl.h
@@ -1801,6 +1801,12 @@ void QgisApp::setupConnections()
connect( mActionUndo, SIGNAL( triggered() ), mUndoWidget, SLOT( undo() ) );
connect( mActionRedo, SIGNAL( triggered() ), mUndoWidget, SLOT( redo() ) );
connect( mUndoWidget, SIGNAL( undoStackChanged() ), this, SLOT( updateUndoActions() ) );

connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
this, SLOT( projectChanged( const QDomDocument & ) ) );
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
this, SLOT( projectChanged( QDomDocument & ) ) );

}

void QgisApp::createCanvas()
@@ -4465,10 +4471,10 @@ void QgisApp::deselectAll()
mMapCanvas->setRenderFlag( false );

QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it!=layers.end(); it++ )
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); it++ )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
if( !vl )
if ( !vl )
continue;

vl->removeSelection();
@@ -6459,8 +6465,35 @@ void QgisApp::updateUndoActions()

void QgisApp::runPythonString( const QString &expr )
{
if ( mPythonUtils )
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
mPythonUtils->runStringUnsafe( expr );
}
}

// add project directory to python path
void QgisApp::projectChanged( const QDomDocument &doc )
{
QgsProject *project = qobject_cast<QgsProject*>( sender() );
if ( !project )
return;

QFileInfo fi( project->fileName() );
if ( !fi.exists() )
return;

static QString prevProjectDir = QString::null;

if ( prevProjectDir == fi.canonicalPath() )
return;

QString expr;
if ( !prevProjectDir.isNull() )
expr = QString( "sys.path.remove('%1'); " ).arg( prevProjectDir );

prevProjectDir = fi.canonicalPath();

expr += QString( "sys.path.append('%1')" ).arg( prevProjectDir );

runPythonString( expr );
}
@@ -59,6 +59,8 @@ class QgsRectangle;
class QgsUndoWidget;
class QgsVectorLayer;

class QDomDocument;

#include <QMainWindow>
#include <QToolBar>
#include <QAbstractSocket>
@@ -631,6 +633,9 @@ class QgisApp : public QMainWindow

void showStyleManagerV2();

//! project changed
void projectChanged( const QDomDocument & );

signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
@@ -59,7 +59,7 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )

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

// import SIP
if ( !runString( "from sip import wrapinstance, unwrapinstance",
@@ -412,9 +412,14 @@ QString QgsPythonUtilsImpl::pluginsPath()
return pythonPath() + "/plugins";
}

QString QgsPythonUtilsImpl::homePythonPath()
{
return QgsApplication::qgisSettingsDirPath() + "/python";
}

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

QStringList QgsPythonUtilsImpl::pluginList()
@@ -89,6 +89,9 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
//! return current path for python plugins
QString pluginsPath();

//! return current path for python in home directory
QString homePythonPath();

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

0 comments on commit c608c0f

Please sign in to comment.