Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Support drag and drop of python scripts onto QGIS window
  • Loading branch information
nyalldawson committed Nov 24, 2014
1 parent fe3e385 commit 9213a84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -4061,7 +4061,18 @@ void QgisApp::openProject( QAction *action )
int myProjectionEnabledFlag =
QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectionsEnabled", 0 );
mMapCanvas->setCrsTransformEnabled( myProjectionEnabledFlag );
} // QgisApp::openProject
}

void QgisApp::runScript( const QString &filePath )
{
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
return;

mPythonUtils->runString(
QString( "import sys\n"
"execfile(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding()))\n" ).arg( filePath )
, tr( "Failed to run Python script:" ), false );
}


/**
Expand Down Expand Up @@ -4154,6 +4165,10 @@ void QgisApp::openFile( const QString & fileName )
{
openLayerDefinition( fileName );
}
else if ( fi.completeSuffix() == "py" )
{
runScript( fileName );
}
else
{
QgsDebugMsg( "Adding " + fileName + " to the map canvas" );
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -853,6 +853,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Open the project file corresponding to the
//! text)= of the given action.
void openProject( QAction *action );
/** Attempts to run a python script
* @param filePath full path to python script
* @note added in QGIS 2.7
*/
void runScript( const QString& filePath );
//! Save the map view as an image - user is prompted for image name using a dialog
void saveMapAsImage();
//! Open a project
Expand Down

0 comments on commit 9213a84

Please sign in to comment.