Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::PythonScript Class Reference

#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)
 

Detailed Description

Class for handling storage, compile and running of Python Scripts. Used by PythonScriptEditor and PythonModule

Constructor & Destructor Documentation

◆ ~PythonScript()

inviwo::PythonScript::~PythonScript ( )

Frees the stored byte code. Make sure that the Python interpreter is still initialized when deleting the script.

Member Function Documentation

◆ getSource()

const std::string & inviwo::PythonScript::getSource ( ) const

Returns the script's source.

◆ run()

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.

Parameters
localsa map of keys and pybind11::object that will available as local variables in the python scripts
callbacka 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
Returns
true, if script execution has been successful

◆ setSource()

void inviwo::PythonScript::setSource ( std::string_view source)

Sets the source for the Python (replacing the current source).


The documentation for this class was generated from the following file: