Version: 6.3.1
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes

PyInterp_Interp Class Reference

Generic embedded Python interpreter.

#include <PyInterp_Interp.h>

Inheritance diagram for PyInterp_Interp:
Inheritance graph

Public Member Functions

 PyInterp_Interp ()
 Basic constructor.
virtual ~PyInterp_Interp ()
 Destructor.
void initialize ()
 Initialize embedded interpreter.
virtual int run (const char *command)
 Run Python command.
PyLockWrapper GetLockWrapper ()
 Get Python GIL wrapper.
std::string getbanner ()
 Get embedded Python interpreter banner.
void setverrcb (PyOutChanged *, void *)
 Set Python standard error device hook.
void setvoutcb (PyOutChanged *, void *)
 Set Python standard output device hook.
const char * getPrevious ()
 Get previous command in the commands history.
const char * getNext ()
 Get next command in the commands history.

Static Public Attributes

static int _argc = 1
static char * _argv [] = {(char*)""}
static PyObject * builtinmodule = NULL
static PyThreadState * _gtstate = NULL
static PyInterpreterState * _interp = NULL

Protected Member Functions

virtual int beforeRun ()
int simpleRun (const char *command, const bool addToHistory=true)
 Run Python command (used internally).
virtual bool initRun ()
 Initialize run command.
virtual void initPython ()
 Initialize Python interpreter.
virtual bool initState ()=0
virtual bool initContext ()=0

Protected Attributes

PyThreadState * _tstate
PyObject * _vout
PyObject * _verr
PyObject * _g
PyObject * _codeop
std::list< std::string > _history
std::list< std::string >::iterator _ith

Constructor & Destructor Documentation

PyInterp_Interp::PyInterp_Interp ( )

After construction the interpreter instance successor classes must call virtual method initalize().

PyInterp_Interp::~PyInterp_Interp ( ) [virtual]

Member Function Documentation

void PyInterp_Interp::initialize ( )

This method shoud be called after construction of the interpreter. The method initialize() calls virtuals methods

  • initPython() to initialize global Python interpreter
  • initState() to initialize embedded interpreter state
  • initContext() to initialize interpreter internal context
  • initRun() to prepare interpreter for running commands which should be implemented in the successor classes, according to the embedded Python interpreter policy (mono or multi interpreter, etc).

References _history, _ith, _tstate, _verr, _vout, initContext(), initPython(), initRun(), initState(), and newPyStdOut().

int PyInterp_Interp::run ( const char *  command) [virtual]
Parameters:
commandPython command
Returns:
command status

Reimplemented in SALOME_PYQT_PyInterp.

References beforeRun(), and simpleRun().

PyLockWrapper PyInterp_Interp::GetLockWrapper ( )
Returns:
GIL lock wrapper (GIL is automatically acquired here)

References _interp, _tstate, and currentThreadMap.

std::string PyInterp_Interp::getbanner ( )
Returns:
banner string
void PyInterp_Interp::setverrcb ( PyOutChanged cb,
void *  data 
)
Parameters:
cbcallback function
datacallback function parameters

References _verr.

void PyInterp_Interp::setvoutcb ( PyOutChanged cb,
void *  data 
)
Parameters:
cbcallback function
datacallback function parameters

References _vout.

const char * PyInterp_Interp::getPrevious ( )
Returns:
previous command

References _history, _ith, and BEGIN_HISTORY_PY.

const char * PyInterp_Interp::getNext ( )
Returns:
next command

References _history, _ith, and TOP_HISTORY_PY.

virtual int PyInterp_Interp.beforeRun ( ) [protected, virtual]

Reimplemented in SalomeApp_PyInterp.

int PyInterp_Interp::simpleRun ( const char *  command,
const bool  addToHistory = true 
) [protected]
Parameters:
commandPython command
addToHistoryif true (default), the command is added to the commands history
Returns:
command status

References _g, _history, _ith, _verr, _vout, and compile_command().

bool PyInterp_Interp::initRun ( ) [protected, virtual]

This method is used to prepare interpreter for running Python commands.

Returns:
true on success and false on error
void PyInterp_Interp::initPython ( ) [protected, virtual]

In case if Python is not initialized, it sets program name, initializes the interpreter, sets program arguments, initializes threads. Otherwise, it just obtains the global interpreter and thread states. This is important for light SALOME configuration, as in full SALOME this is done at SalomeApp level.

See also:
SalomeApp_PyInterp class

Reimplemented in LightApp_PyInterp, SALOME_PYQT_PyInterp, and SalomeApp_PyInterp.

References _argc, _argv, _gtstate, and _interp.

virtual bool PyInterp_Interp.initState ( ) [protected, pure virtual]

Implemented in PyConsole_Interp, and SALOME_PYQT_PyInterp.

virtual bool PyInterp_Interp.initContext ( ) [protected, pure virtual]

Field Documentation

int PyInterp_Interp::_argc = 1 [static]
char * PyInterp_Interp::_argv = {(char*)""} [static]
PyObject * PyInterp_Interp::builtinmodule = NULL [static]
PyThreadState * PyInterp_Interp::_gtstate = NULL [static]
PyInterpreterState * PyInterp_Interp::_interp = NULL [static]
PyThreadState* PyInterp_Interp._tstate [protected]
PyObject* PyInterp_Interp._vout [protected]
PyObject* PyInterp_Interp._verr [protected]
PyObject* PyInterp_Interp._g [protected]
PyObject* PyInterp_Interp._codeop [protected]
std::list<std::string> PyInterp_Interp._history [protected]
std::list<std::string>::iterator PyInterp_Interp._ith [protected]
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS