Inviwo
0.9.10.1
Inviwo documentation
|
#include <pythonscript.h>
Public Member Functions | |
virtual | ~PythonScript () |
void | setSource (const std::string &source) |
std::string | getSource () const |
bool | run (std::unordered_map< std::string, pybind11::object > locals=std::unordered_map< std::string, pybind11::object >{}, std::function< void(pybind11::dict)> callback=nullptr) |
bool | run (std::function< void(pybind11::dict)> callback) |
bool | run (pybind11::dict locals, std::function< void(pybind11::dict)> callback=nullptr) |
virtual void | setFilename (const std::string &filename) |
const std::string & | getFilename () const |
Class for handling storage, compile and running of Python Scripts. Used by PythonScriptEditor and PythonModule
|
virtual |
Frees the stored byte code. Make sure that the Python interpreter is still initialized when deleting the script.
std::string inviwo::PythonScript::getSource | ( | ) | const |
Returns the script's source.
bool inviwo::PythonScript::run | ( | std::unordered_map< std::string, pybind11::object > | locals = std::unordered_map<std::string, pybind11::object>{} , |
std::function< void(pybind11::dict)> | callback = nullptr |
||
) |
Runs the script once. If the script has changed since last compile a new compile call will be issued.
If an error occurs, the error message is logged to the inviwo logger and python standard output.
locals | a map of keys and pybind11::object that will available as local variables in the python scripts |
callback | a callback that will be called once the script has finished executing. The callback takes a pybind11::dict) representing the python dict of local variables from the script. Can be used to parse results from the script. This callback will only be called of the script executed with out problems |
void inviwo::PythonScript::setSource | ( | const std::string & | source | ) |
Sets the source for the Python (replacing the current source).