Skip to content
Permalink
Browse files

[FEATURE] Support drag and drop of python scripts onto QGIS window

  • Loading branch information
nyalldawson committed Nov 24, 2014
1 parent fe3e385 commit 9213a845a59f11b4935465ce25703a11fda9b64c
Showing with 21 additions and 1 deletion.
  1. +16 −1 src/app/qgisapp.cpp
  2. +5 −0 src/app/qgisapp.h
@@ -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 );
}


/**
@@ -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" );
@@ -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

0 comments on commit 9213a84

Please sign in to comment.
You can’t perform that action at this time.