QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgspythonrunner.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspythonrunner.h
3 ---------------------
4 begin : May 2011
5 copyright : (C) 2011 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSPYTHONRUNNER_H
16#define QGSPYTHONRUNNER_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20
21#include <QString>
22
32class CORE_EXPORT QgsPythonRunner
33{
34 public:
39 static bool isValid();
40
42 static bool run( const QString &command, const QString &messageOnError = QString() );
43
48 static bool runFile( const QString &filename, const QString &messageOnError = QString() );
49
51 static bool eval( const QString &command, QString &result SIP_OUT );
52
54 static bool setArgv( const QStringList &arguments, const QString &messageOnError = QString() );
55
61 static void setInstance( QgsPythonRunner *runner SIP_TRANSFER );
62
63 protected:
65 QgsPythonRunner() = default;
66 virtual ~QgsPythonRunner() = default;
67
69 virtual bool runCommand( QString command, QString messageOnError = QString() ) = 0;
70
72 virtual bool runFileCommand( const QString &filename, const QString &messageOnError = QString() ) = 0;
73
75 virtual bool evalCommand( QString command, QString &result ) = 0;
76
78 virtual bool setArgvCommand( const QStringList &arguments, const QString &messageOnError = QString() ) = 0;
79
81};
82
83#endif // QGSPYTHONRUNNER_H
static bool setArgv(const QStringList &arguments, const QString &messageOnError=QString())
Set sys.argv.
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a Python statement.
virtual bool evalCommand(QString command, QString &result)=0
Evaluates the given expression, producing a result.
virtual bool runFileCommand(const QString &filename, const QString &messageOnError=QString())=0
Runs the code from the given file.
static void setInstance(QgsPythonRunner *runner)
Assign an instance of Python runner so that run() can be used.
static bool eval(const QString &command, QString &result)
Eval a Python statement.
virtual bool runCommand(QString command, QString messageOnError=QString())=0
Runs the given statement.
virtual ~QgsPythonRunner()=default
virtual bool setArgvCommand(const QStringList &arguments, const QString &messageOnError=QString())=0
Sets sys.argv to the given arguments.
static QgsPythonRunner * sInstance
static bool runFile(const QString &filename, const QString &messageOnError=QString())
Execute a Python filename, showing an error message if one occurred.
static bool isValid()
Returns true if the runner has an instance (and thus is able to run commands).
QgsPythonRunner()=default
Protected constructor: can be instantiated only from children.
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57