Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Add --code arg to run python code on qgis load
  • Loading branch information
NathanW2 committed Nov 16, 2012
1 parent e3d30af commit bfa08c5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/app/main.cpp
Expand Up @@ -35,6 +35,7 @@
#include "qgscustomization.h"
#include "qgspluginregistry.h"
#include "qgsmessagelog.h"
#include "qgspythonrunner.h"

#include <cstdio>
#include <stdio.h>
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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}
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 != "" )
Expand Down Expand Up @@ -797,7 +819,6 @@ int main( int argc, char *argv[] )
return 1;
}


/////////////////////////////////////////////////////////////////////
// Continue on to interactive gui...
/////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit bfa08c5

Please sign in to comment.