Base::InterpreterSingleton Class Reference

The Interpreter class This class manage the python interpreter and hold a lot helper functions for handling python stuff. More...

#include <Interpreter.h>

Public Member Functions

 InterpreterSingleton ()
 
 ~InterpreterSingleton ()
 
execution methods
std::string runString (const char *psCmd)
 Run a statement on the python interpreter and gives back a string with the representation of the result. More...
 
std::string runStringWithKey (const char *psCmd, const char *key, const char *key_initial_value="")
 Run a statement on the python interpreter with a key for exchanging strings. More...
 
Py::Object runStringObject (const char *sCmd)
 Run a statement on the python interpreter and return back the result object. More...
 
void runInteractiveString (const char *psCmd)
 Run a statement on the python interpreter and gives back a string with the representation of the result. More...
 
void runFile (const char *pxFileName, bool local)
 Run file (script) on the python interpreter. More...
 
void runStringArg (const char *psCom,...)
 Run a statement with arguments on the python interpreter. More...
 
void runMethodVoid (PyObject *pobject, const char *method)
 runs a python object method with no return value and no arguments More...
 
PyObjectrunMethodObject (PyObject *pobject, const char *method)
 runs a python object method which returns a arbitrary object More...
 
void runMethod (PyObject *pobject, const char *method, const char *resfmt=nullptr, void *cresult=nullptr, const char *argfmt="()",...)
 runs a python method with arbitrary params More...
 
Cleanup
int cleanup (void(*func)())
 Register a cleanup function to be called by finalize(). More...
 
void finalize ()
 This calls the registered cleanup functions. More...
 
void systemExit ()
 This shuts down the application. More...
 
external wrapper libs

here we can access external dynamically loaded wrapper libs done e.g.

by SWIG or SIP

PyObjectcreateSWIGPointerObj (const char *Modole, const char *TypeName, void *Pointer, int own)
 generate a SWIG object More...
 
bool convertSWIGPointerObj (const char *Module, const char *TypeName, PyObject *obj, void **ptr, int flags)
 
void cleanupSWIG (const char *TypeName)
 
PyTypeObject * getSWIGPointerTypeObj (const char *Module, const char *TypeName)
 
methods for debugging facility
void dbgObserveFile (const char *sFileName="")
 sets the file name which should be debugged More...
 
void dbgSetBreakPoint (unsigned int uiLineNumber)
 sets a break point to a special line number in the current file More...
 
void dbgUnsetBreakPoint (unsigned int uiLineNumber)
 unsets a break point to a special line number in the current file More...
 
void dbgStep ()
 One step further. More...
 

Module handling

bool loadModule (const char *psModName)
 
void addPythonPath (const char *Path)
 Add an additional python path. More...
 
PyObjectaddModule (Py::ExtensionModuleBase *)
 Add a module and return a PyObject to it. More...
 
void cleanupModules ()
 Clean-up registered modules. More...
 
static void addType (PyTypeObject *Type, PyObject *Module, const char *Name)
 

startup and singletons

const char * init (int argc, char *argv[])
 init the interpreter and returns the module search path More...
 
int runCommandLine (const char *prompt)
 
void replaceStdOutput ()
 
static InterpreterSingletonInstance ()
 
static void Destruct ()
 

static helper functions

PyObjectgetValue (const char *key, const char *result_var)
 
static const std::string strToPython (const char *Str)
 replaces all char with escapes for usage in python console More...
 
static const std::string strToPython (const std::string &Str)
 

Detailed Description

The Interpreter class This class manage the python interpreter and hold a lot helper functions for handling python stuff.

Constructor & Destructor Documentation

◆ InterpreterSingleton()

InterpreterSingleton::InterpreterSingleton ( )

Referenced by Instance().

◆ ~InterpreterSingleton()

InterpreterSingleton::~InterpreterSingleton ( )

Member Function Documentation

◆ addModule()

◆ addPythonPath()

void InterpreterSingleton::addPythonPath ( const char *  Path)

Add an additional python path.

Referenced by App::Application::processFiles().

◆ addType()

void InterpreterSingleton::addType ( PyTypeObject *  Type,
PyObject Module,
const char *  Name 
)
static

◆ cleanup()

int InterpreterSingleton::cleanup ( void(*)()  func)

Register a cleanup function to be called by finalize().

The cleanup function will be called with no arguments and should return no value. At most 32 cleanup functions can be registered. When the registration is successful 0 is returned; on failure -1 is returned. The cleanup function registered last is called first. Each cleanup function will be called at most once. Since Python's internal finalization will have completed before the cleanup function, no Python APIs should be called by func.

Referenced by PathPythonGui.simple_edit_panel.SimpleEditPanel::abort(), PathScripts.PathDressupPathBoundaryGui.TaskPanel::abort(), PathScripts.PathDressupTagGui.PathDressupTagTaskPanel::abort(), PathScripts.PathDressupDogbone.TaskPanel::accept(), PathScripts.PathDressupPathBoundaryGui.TaskPanel::accept(), PathScripts.PathDressupTagGui.PathDressupTagTaskPanel::accept(), PathScripts.PathJobGui.TaskPanel::accept(), PathScripts.PathOpGui.TaskPanel::accept(), PathScripts.PathDressupDogbone.TaskPanel::reject(), PathScripts.PathDressupPathBoundaryGui.TaskPanel::reject(), PathScripts.PathDressupTagGui.PathDressupTagTaskPanel::reject(), PathScripts.PathJobGui.TaskPanel::reject(), and PathScripts.PathOpGui.TaskPanel::reject().

◆ cleanupModules()

void InterpreterSingleton::cleanupModules ( )

Clean-up registered modules.

Referenced by finalize().

◆ cleanupSWIG()

void InterpreterSingleton::cleanupSWIG ( const char *  TypeName)

◆ convertSWIGPointerObj()

◆ createSWIGPointerObj()

◆ dbgObserveFile()

void InterpreterSingleton::dbgObserveFile ( const char *  sFileName = "")

sets the file name which should be debugged

◆ dbgSetBreakPoint()

void InterpreterSingleton::dbgSetBreakPoint ( unsigned int  uiLineNumber)

sets a break point to a special line number in the current file

◆ dbgStep()

void InterpreterSingleton::dbgStep ( )

One step further.

◆ dbgUnsetBreakPoint()

void InterpreterSingleton::dbgUnsetBreakPoint ( unsigned int  uiLineNumber)

unsets a break point to a special line number in the current file

◆ Destruct()

void InterpreterSingleton::Destruct ( )
static

◆ finalize()

void InterpreterSingleton::finalize ( )

This calls the registered cleanup functions.

See also
cleanup() for more details.

References cleanupModules().

Referenced by App::Application::destruct(), and draftguitools.gui_trackers.ghostTracker::remove().

◆ getSWIGPointerTypeObj()

PyTypeObject * InterpreterSingleton::getSWIGPointerTypeObj ( const char *  Module,
const char *  TypeName 
)

◆ getValue()

PyObject * InterpreterSingleton::getValue ( const char *  key,
const char *  result_var 
)

◆ init()

const char * InterpreterSingleton::init ( int  argc,
char *  argv[] 
)

init the interpreter and returns the module search path

References PythonStdOutput::init_type().

Referenced by DocumentObject.DocumentObject::onChanged().

◆ Instance()

InterpreterSingleton & InterpreterSingleton::Instance ( )
static

References InterpreterSingleton().

Referenced by Base::Interpreter().

◆ loadModule()

bool InterpreterSingleton::loadModule ( const char *  psModName)

◆ replaceStdOutput()

void InterpreterSingleton::replaceStdOutput ( )

◆ runCommandLine()

int InterpreterSingleton::runCommandLine ( const char *  prompt)

◆ runFile()

void InterpreterSingleton::runFile ( const char *  pxFileName,
bool  local 
)

◆ runInteractiveString()

void InterpreterSingleton::runInteractiveString ( const char *  psCmd)

Run a statement on the python interpreter and gives back a string with the representation of the result.

References Base::Exception::setMessage().

◆ runMethod()

void InterpreterSingleton::runMethod ( PyObject pobject,
const char *  method,
const char *  resfmt = nullptr,
void *  cresult = nullptr,
const char *  argfmt = "()",
  ... 
)

runs a python method with arbitrary params

Referenced by Gui::PythonCommand::activated().

◆ runMethodObject()

PyObject * InterpreterSingleton::runMethodObject ( PyObject pobject,
const char *  method 
)

runs a python object method which returns a arbitrary object

Referenced by Gui::PythonCommand::getHelpUrl(), Gui::PythonCommand::PythonCommand(), and Gui::PythonGroupCommand::PythonGroupCommand().

◆ runMethodVoid()

void InterpreterSingleton::runMethodVoid ( PyObject pobject,
const char *  method 
)

runs a python object method with no return value and no arguments

Runs a member method of an object with no parameter and no return value void (void).

There are other methods to run with returns

Referenced by Gui::PythonCommand::activated().

◆ runString()

◆ runStringArg()

◆ runStringObject()

Py::Object InterpreterSingleton::runStringObject ( const char *  sCmd)

Run a statement on the python interpreter and return back the result object.

◆ runStringWithKey()

std::string InterpreterSingleton::runStringWithKey ( const char *  psCmd,
const char *  key,
const char *  key_initial_value = "" 
)

Run a statement on the python interpreter with a key for exchanging strings.

runStringWithKey(psCmd, key, key_initial_value) psCmd is python script to run key is the name of a python string variable the script will have read/write access to during script execution.

It will be our return value. key_initial_value is the initial value c++ will set before calling the script If the script runs successfully it will be able to change the value of key as the return value, but if there is a runtime error key will not be changed even if the error occurs after changing it inside the script.

References Base::PyException::ThrowException().

◆ strToPython() [1/2]

const std::string InterpreterSingleton::strToPython ( const char *  Str)
static

◆ strToPython() [2/2]

static const std::string Base::InterpreterSingleton::strToPython ( const std::string &  Str)
static

References strToPython().

Referenced by strToPython().

◆ systemExit()

void InterpreterSingleton::systemExit ( )

This shuts down the application.


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