Skip to content
Permalink
Browse files

[FEATURE] Add --code arg to run python code on qgis load

  • Loading branch information
NathanW2 committed Nov 16, 2012
1 parent e3d30af commit bfa08c5f06253b256b2000b790a29ee58bccd6f7
Showing with 23 additions and 2 deletions.
  1. +23 −2 src/app/main.cpp
@@ -35,6 +35,7 @@
#include "qgscustomization.h"
#include "qgspluginregistry.h"
#include "qgsmessagelog.h"
#include "qgspythonrunner.h"

#include <cstdio>
#include <stdio.h>
@@ -106,6 +107,7 @@ void usage( std::string const & appName )
<< "\t[--nocustomization]\tdon't apply GUI customization\n"
<< "\t[--optionspath path]\tuse the given QSettings path\n"
<< "\t[--configpath path]\tuse the given path for all user configuration\n"
<< "\t[--code path]\tRun the given python file on load. \n"
<< "\t[--help]\t\tthis text\n\n"
<< " FILES:\n"
<< " Files specified on the command line can include rasters,\n"
@@ -266,6 +268,8 @@ int main( int argc, char *argv[] )
QString configpath;
QString optionpath;

QString pythonfile;

#if defined(ANDROID)
QgsDebugMsg( QString( "Android: All params stripped" ) );// Param %1" ).arg( argv[0] ) );
//put all QGIS settings in the same place
@@ -325,6 +329,10 @@ int main( int argc, char *argv[] )
{
configpath = argv[++i];
}
else if ( i + 1 < argc && ( arg == "--code" || arg == "-f" ) )
{
pythonfile = argv[++i];
}
else
{
myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
@@ -358,6 +366,7 @@ int main( int argc, char *argv[] )
{"extent", required_argument, 0, 'e'},
{"optionspath", required_argument, 0, 'o'},
{"configpath", required_argument, 0, 'c'},
{"code", required_argument, 0, 'f'},
{"android", required_argument, 0, 'a'},
{0, 0, 0, 0}
};
@@ -428,6 +437,10 @@ int main( int argc, char *argv[] )
configpath = optarg;
break;

case 'f':
pythonfile = optarg;
break;

case '?':
usage( argv[0] );
return 2; // XXX need standard exit codes
@@ -769,7 +782,16 @@ int main( int argc, char *argv[] )
}
}

/////////////////////////////////////////////////////////////////////
if ( !pythonfile.isEmpty() )
{
#ifdef Q_WS_WIN
//replace backslashes with forward slashes
pythonfile.replace( "\\", "/" );
#endif
QgsPythonRunner::run(QString("execfile('%1')").arg(pythonfile));
}

/////////////////////////////////`////////////////////////////////////
// Take a snapshot of the map view then exit if snapshot mode requested
/////////////////////////////////////////////////////////////////////
if ( mySnapshotFileName != "" )
@@ -797,7 +819,6 @@ int main( int argc, char *argv[] )
return 1;
}


/////////////////////////////////////////////////////////////////////
// Continue on to interactive gui...
/////////////////////////////////////////////////////////////////////

0 comments on commit bfa08c5

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