ImFusion C++ SDK 4.4.0
ImFusion::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 ImFusion::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 destroyInteractiveConsole (MainWindowBase *main)
void setApplicationController (ApplicationController &app) override

Additional Inherited Members

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

Member Function Documentation

◆ version()

std::string ImFusion::PythonInterpreter::version ( ) const
overridevirtual

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

Implements ImFusion::PythonInterpreterInterface.

◆ bridgeDirectory()

const std::string & ImFusion::PythonInterpreter::bridgeDirectory ( ) const
overridevirtual

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

Implements ImFusion::PythonInterpreterInterface.

◆ gil_scoped_acquire()

std::unique_ptr< GILScopeGuard > ImFusion::PythonInterpreter::gil_scoped_acquire ( )
overridevirtual

◆ gil_scoped_release()

std::unique_ptr< GILScopeGuard > ImFusion::PythonInterpreter::gil_scoped_release ( )
overridevirtual

◆ eval()

std::vector< std::shared_ptr< Data > > ImFusion::PythonInterpreter::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 ImFusion::PythonInterpreterInterface.

◆ eval_file()

void ImFusion::PythonInterpreter::eval_file ( std::string filename)
overridevirtual

Calls pybind11::eval_file Raises an exception on error.

Implements ImFusion::PythonInterpreterInterface.

◆ exec()

void ImFusion::PythonInterpreter::exec ( std::string expr)
overridevirtual

Calls pybind11::exec Raises an exception on error.

Implements ImFusion::PythonInterpreterInterface.

◆ start()

void ImFusion::PythonInterpreter::start ( )
overridevirtual

Starts the interpreter and imports the imfusion module.

Throws a runtime_error if interpreter or module could not be initialized

Implements ImFusion::PythonInterpreterInterface.

◆ createFactoriesPlugin()

std::unique_ptr< ImFusionPlugin > ImFusion::PythonInterpreter::createFactoriesPlugin ( )
overridevirtual

◆ createInteractiveConsole()

void ImFusion::PythonInterpreter::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 ImFusion::PythonInterpreterInterface.

◆ setApplicationController()

void ImFusion::PythonInterpreter::setApplicationController ( ApplicationController & app)
overridevirtual

The documentation for this class was generated from the following file:
  • ImFusion/Python/PythonInterpreter.h
Search Tab / S to search, Esc to close