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.

Methods

evalCommand

runCommand

Static Methods

eval

Eval a Python statement

isValid

Returns True if the runner has an instance (and thus is able to run commands)

run

Execute a Python statement

setInstance

Assign an instance of Python runner so that run() can be used.

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)

evalCommand(self, command: str | None, result: str | None) bool[source]
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

runCommand(self, command: str | None, messageOnError: str | None = '') bool[source]
Parameters:
  • command (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])