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 extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l);
29 #define TOP_HISTORY_PY "--- top of history ---"
30 #define BEGIN_HISTORY_PY "--- begin of history ---"
32 class PYINTERP_EXPORT PyLockWrapper
34 PyThreadState* myThreadState;
35 PyThreadState* mySaveThreadState;
37 PyLockWrapper(PyThreadState* theThreadState);
42 class PYINTERP_EXPORT PyInterp_base{
46 static PyObject *builtinmodule;
51 virtual void initialize();
52 static void init_python();
54 virtual int run(const char *command);
56 PyLockWrapper GetLockWrapper();
58 std::string getbanner();
59 std::string getverr();
60 std::string getvout();
62 const char * getPrevious();
63 const char * getNext();
66 PyThreadState * _tstate;
71 std::list<std::string> _history;
72 std::list<std::string>::iterator _ith;
75 int simpleRun(const char* command);
78 virtual bool initState() = 0;
79 virtual bool initContext() = 0;
83 class PYINTERP_EXPORT PyObjWrapper{
86 PyObjWrapper(PyObject* theObject): myObject(theObject) {}
87 PyObjWrapper(): myObject(0) {}
91 PyObject* operator->(){
100 bool operator==(PyObject* theObject){
101 return myObject == theObject;
103 PyObject** operator&(){
106 PyObjWrapper& operator=(PyObjWrapper* theObjWrapper){
107 Py_XDECREF(myObject);
108 myObject = theObjWrapper->myObject;
111 virtual ~PyObjWrapper(){
112 Py_XDECREF(myObject);