Class: QgsPythonRunner¶
Utility class for running Python commands from various parts of QGIS.
There is no direct Python support in the core library, so it is expected that application with Python support creates a subclass that implements pure virtual function(s) during the initialization. The static methods will then work as expected.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: evalCommand()
, runCommand()
, runFileCommand()
, setArgvCommand()
Abstract Methods
Evaluates the given expression, producing a result. |
|
Runs the given statement. |
|
Runs the code from the given file. |
|
Sets sys.argv to the given arguments. |
Static Methods
Eval a Python statement |
|
Returns |
|
Execute a Python statement |
|
Execute a Python filename, showing an error message if one occurred. |
|
Set sys.argv |
|
Assign an instance of Python runner so that |
- class qgis.core.QgsPythonRunner[source]¶
Bases:
object
- __init__()
Protected constructor: can be instantiated only from children
- __init__(a0: QgsPythonRunner)
- Parameters:
a0 (QgsPythonRunner)
- static eval(command: str | None)[source]¶
Eval a Python statement
- Parameters:
command (Optional[str]) -> (bool)
- abstract evalCommand(self, command: str | None, result: str | None) bool [source]¶
Evaluates the given expression, producing a result.
- Parameters:
command (Optional[str])
result (Optional[str])
- Return type:
bool
- static isValid() bool [source]¶
Returns
True
if the runner has an instance (and thus is able to run commands)- Return type:
bool
- static run(command: str | None, messageOnError: str | None = '') bool [source]¶
Execute a Python statement
- Parameters:
command (Optional[str])
messageOnError (Optional[str] = '')
- Return type:
bool
- abstract runCommand(self, command: str | None, messageOnError: str | None = '') bool [source]¶
Runs the given statement.
- Parameters:
command (Optional[str])
messageOnError (Optional[str] = '')
- Return type:
bool
- static runFile(filename: str | None, messageOnError: str | None = '') bool [source]¶
Execute a Python
filename
, showing an error message if one occurred.- Return type:
bool
- Returns:
true if no error occurred
- Parameters:
filename (Optional[str])
messageOnError (Optional[str] = '')
- abstract runFileCommand(self, filename: str | None, messageOnError: str | None = '') bool [source]¶
Runs the code from the given file.
- Parameters:
filename (Optional[str])
messageOnError (Optional[str] = '')
- Return type:
bool
- static setArgv(arguments: Iterable[str | None], messageOnError: str | None = '') bool [source]¶
Set sys.argv
- Parameters:
arguments (Iterable[Optional[str]])
messageOnError (Optional[str] = '')
- Return type:
bool
- abstract setArgvCommand(self, arguments: Iterable[str | None], messageOnError: str | None = '') bool [source]¶
Sets sys.argv to the given arguments.
- Parameters:
arguments (Iterable[Optional[str]])
messageOnError (Optional[str] = '')
- Return type:
bool
- static setInstance(runner: QgsPythonRunner | None)[source]¶
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.- Parameters:
runner (Optional[QgsPythonRunner])