Inviwo 0.9.12-pre
Inviwo documentation
|
#include <pythonscript.h>
Public Member Functions | |
PythonScript (std::string_view source="", std::string_view name="") | |
~PythonScript () | |
void | setSource (std::string_view source) |
const std::string & | getSource () const |
void | setName (std::string_view name) |
const std::string & | getName () 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) |
Static Public Member Functions | |
static PythonScript | fromFile (const std::filesystem::path &path) |
Class for handling storage, compile and running of Python Scripts. Used by PythonScriptEditor and PythonModule
inviwo::PythonScript::~PythonScript | ( | ) |
Frees the stored byte code. Make sure that the Python interpreter is still initialized when deleting the script.
const 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 | ( | std::string_view | source | ) |
Sets the source for the Python (replacing the current source).