Skip to content

Commit

Permalink
Add eval to QgsPythonRunner.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Mar 30, 2013
1 parent 67b9c48 commit 0229ea9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/core/qgspythonrunner.sip
Expand Up @@ -12,6 +12,9 @@ class QgsPythonRunner
/** execute a python statement */
static bool run( QString command, QString messageOnError = QString() );

/** Eval a python statement */
static bool eval( QString command, QString& result);

/** assign an instance of python runner so that run() can be used.
This method should be called during app initialization.
Takes ownership of the object, deletes previous instance. */
Expand All @@ -23,4 +26,6 @@ class QgsPythonRunner
virtual ~QgsPythonRunner();

virtual bool runCommand( QString command, QString messageOnError = QString() ) = 0;

virtual bool evalCommand( QString command, QString& result ) = 0;
};
10 changes: 10 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -6232,6 +6232,7 @@ class QgsPythonRunnerImpl : public QgsPythonRunner
{
public:
QgsPythonRunnerImpl( QgsPythonUtils* pythonUtils ) : mPythonUtils( pythonUtils ) {}

virtual bool runCommand( QString command, QString messageOnError = QString() )
{
if ( mPythonUtils && mPythonUtils->isEnabled() )
Expand All @@ -6241,6 +6242,15 @@ class QgsPythonRunnerImpl : public QgsPythonRunner
return false;
}

virtual bool evalCommand( QString command, QString &result )
{
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
return mPythonUtils->evalString( command, result );
}
return false;
}

protected:
QgsPythonUtils* mPythonUtils;
};
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgspythonrunner.cpp
Expand Up @@ -38,6 +38,19 @@ bool QgsPythonRunner::run( QString command, QString messageOnError )
}
}

bool QgsPythonRunner::eval( QString command, QString& result )
{
if ( mInstance )
{
return mInstance->evalCommand( command, result );
}
else
{
QgsDebugMsg( "Unable to run Python command: runner not available!" );
return false;
}
}

void QgsPythonRunner::setInstance( QgsPythonRunner* runner )
{
delete mInstance;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgspythonrunner.h
Expand Up @@ -37,6 +37,9 @@ class CORE_EXPORT QgsPythonRunner
/** execute a python statement */
static bool run( QString command, QString messageOnError = QString() );

/** Eval a python statement */
static bool eval( QString command, QString& result);

/** assign an instance of python runner so that run() can be used.
This method should be called during app initialization.
Takes ownership of the object, deletes previous instance. */
Expand All @@ -49,6 +52,8 @@ class CORE_EXPORT QgsPythonRunner

virtual bool runCommand( QString command, QString messageOnError = QString() ) = 0;

virtual bool evalCommand( QString command, QString& result ) = 0;

static QgsPythonRunner* mInstance;
};

Expand Down

0 comments on commit 0229ea9

Please sign in to comment.