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 ...
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 static void init_python();
56 virtual int run(const char *command);
58 PyLockWrapper GetLockWrapper();
60 std::string getbanner();
61 std::string getverr();
62 std::string getvout();
64 const char * getPrevious();
65 const char * getNext();
68 PyThreadState * _tstate;
73 std::list<std::string> _history;
74 std::list<std::string>::iterator _ith;
77 int simpleRun(const char* command);
80 virtual bool initState() = 0;
81 virtual bool initContext() = 0;
85 class PYINTERP_EXPORT PyObjWrapper{
88 PyObjWrapper(PyObject* theObject): myObject(theObject) {}
89 PyObjWrapper(): myObject(0) {}
93 PyObject* operator->(){
102 bool operator==(PyObject* theObject){
103 return myObject == theObject;
105 PyObject** operator&(){
108 PyObjWrapper& operator=(PyObjWrapper* theObjWrapper){
109 Py_XDECREF(myObject);
110 myObject = theObjWrapper->myObject;
113 virtual ~PyObjWrapper(){
114 Py_XDECREF(myObject);