ImFusion SDK 4.3
PythonInterpreter Class Reference

#include <ImFusion/Python/PythonInterpreter.h>

Starts an embedded Python interpreter and provides factories for registering algorithms from Python. More...

+ Inheritance diagram for PythonInterpreter:

Detailed Description

Starts an embedded Python interpreter and provides factories for registering algorithms from Python.

This class should only be used by the PythonPlugin.

Public Member Functions

 PythonInterpreter (const std::string &libpythonPath, const std::string &imfusionInterpreterDLLPath, const std::wstring &pythonExecutable, const std::string &envName)
 Does not initialize or start the interpreter yet.
 
 ~PythonInterpreter () override
 Stops the interpreter if it was started.
 
std::string version () const override
 Returns the Python version of this interpreter (e.g. "3.6")
 
const std::stringbridgeDirectory () const override
 Returns the runtime directory from where interpreter bridge plugins can be loaded.
 
std::unique_ptr< GILScopeGuardgil_scoped_acquire () override
 
std::unique_ptr< GILScopeGuardgil_scoped_release () override
 
std::vector< std::shared_ptr< Data > > eval (const std::string &expr, const dict &localData=dict()) override
 Evaluates a Python expression via pybind11::eval, passing it a set of local data, and returns a vector of Data returned by the expression.
 
void eval_file (std::string filename) override
 Calls pybind11::eval_file Raises an exception on error.
 
void exec (std::string expr) override
 Calls pybind11::exec Raises an exception on error.
 
void start () override
 Starts the interpreter and imports the imfusion module.
 
std::unique_ptr< ImFusionPlugincreateFactoriesPlugin () override
 
void createInteractiveConsole (MainWindowBase *main) override
 Creates an interactive console widget in the MainWindow.
 
void setApplicationController (ApplicationController &app) override
 

Additional Inherited Members

- Public Types inherited from PythonInterpreterInterface
using dict = std::unordered_map<std::string, std::shared_ptr<Data>>
 
- Protected Member Functions inherited from PythonInterpreterInterface
 PythonInterpreterInterface (const std::string &)
 

Member Function Documentation

◆ version()

std::string version ( ) const
overridevirtual

Returns the Python version of this interpreter (e.g. "3.6")

Implements PythonInterpreterInterface.

◆ bridgeDirectory()

const std::string & bridgeDirectory ( ) const
overridevirtual

Returns the runtime directory from where interpreter bridge plugins can be loaded.

Implements PythonInterpreterInterface.

◆ gil_scoped_acquire()

std::unique_ptr< GILScopeGuard > gil_scoped_acquire ( )
overridevirtual

◆ gil_scoped_release()

std::unique_ptr< GILScopeGuard > gil_scoped_release ( )
overridevirtual

◆ eval()

std::vector< std::shared_ptr< Data > > eval ( const std::string & expr,
const dict & localData = dict() )
overridevirtual

Evaluates a Python expression via pybind11::eval, passing it a set of local data, and returns a vector of Data returned by the expression.

The Python expression is expected to return a Data or a list/tuple/dictionary of Data that are bound. Throws a C++ exception if the expression raises a Python exception.

Implements PythonInterpreterInterface.

◆ eval_file()

void eval_file ( std::string filename)
overridevirtual

Calls pybind11::eval_file Raises an exception on error.

Implements PythonInterpreterInterface.

◆ exec()

void exec ( std::string expr)
overridevirtual

Calls pybind11::exec Raises an exception on error.

Implements PythonInterpreterInterface.

◆ start()

void start ( )
overridevirtual

Starts the interpreter and imports the imfusion module.

Throws a runtime_error if interpreter or module could not be initialized

Implements PythonInterpreterInterface.

◆ createFactoriesPlugin()

std::unique_ptr< ImFusionPlugin > createFactoriesPlugin ( )
overridevirtual

◆ createInteractiveConsole()

void createInteractiveConsole ( MainWindowBase * main)
overridevirtual

Creates an interactive console widget in the MainWindow.

The widget is added to a layout with the object name of "logViewerContainer". If no such widget exists in main, the console is launch in a separate window.

What kind of widget is created depends on the PythonSettings::consoleType setting value. With the default value of PythonSettings::NoConsole, no widget is created.

The created widget has an object name of "pythonConsoleWidget". Any existing "pythonConsoleWidget" is deleted when this method is called.

Implements PythonInterpreterInterface.

◆ setApplicationController()

void setApplicationController ( ApplicationController & app)
overridevirtual

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close