Inviwo  0.9.10.1
Inviwo documentation
inviwo::PythonScript Class Reference

#include <pythonscript.h>

+ Inheritance diagram for inviwo::PythonScript:

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
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ~PythonScript()

inviwo::PythonScript::~PythonScript ( )
virtual

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

Member Function Documentation

◆ getSource()

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 ( const std::string &  source)

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


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