1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : PyInterp_base.h
8 // Author : Christian CAREMOLI, Paul RASCLE, EDF
12 #ifndef _PYINTERP_BASE_H_
13 #define _PYINTERP_BASE_H_
21 // include order important!
22 // pthread then python then qt
23 //#include <pthread.h> // must be before Python.h !
25 #include <Python.h> // must be before qt includes ...
27 #if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0
28 extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l);
31 #define TOP_HISTORY_PY "--- top of history ---"
32 #define BEGIN_HISTORY_PY "--- begin of history ---"
34 class PYINTERP_EXPORT PyLockWrapper
36 PyThreadState* myThreadState;
37 PyThreadState* mySaveThreadState;
39 PyLockWrapper(PyThreadState* theThreadState);
44 class PYINTERP_EXPORT PyInterp_base{
48 static PyObject *builtinmodule;
53 virtual void initialize();
54 virtual void init_python();
55 // init_python() made virtual to:
56 // 1. Remove dependency on KERNEL in light SALOME configuration
57 // 2. Allow redefinition of this method in SalomeApp_PyInterp class (it should be empty there and rely on KERNEL_PYTHON)
59 virtual int run(const char *command);
61 PyLockWrapper GetLockWrapper();
63 std::string getbanner();
64 std::string getverr();
65 std::string getvout();
67 const char * getPrevious();
68 const char * getNext();
71 PyThreadState * _tstate;
76 std::list<std::string> _history;
77 std::list<std::string>::iterator _ith;
80 int simpleRun(const char* command);
83 virtual bool initState() = 0;
84 virtual bool initContext() = 0;
88 class PYINTERP_EXPORT PyObjWrapper{
91 PyObjWrapper(PyObject* theObject): myObject(theObject) {}
92 PyObjWrapper(): myObject(0) {}
96 PyObject* operator->(){
105 bool operator==(PyObject* theObject){
106 return myObject == theObject;
108 PyObject** operator&(){
111 PyObjWrapper& operator=(PyObjWrapper* theObjWrapper){
112 Py_XDECREF(myObject);
113 myObject = theObjWrapper->myObject;
116 virtual ~PyObjWrapper(){
117 Py_XDECREF(myObject);