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_
19 // include order important!
20 // pthread then python then qt
21 #include <pthread.h> // must be before Python.h !
22 #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 ---"
34 QSemaphore* mySemaphore;
35 std::string myComment;
37 SemaphoreLock(QSemaphore* theSemaphore, const char* theComment = "");
43 PyThreadState* myThreadState;
44 PyThreadState* mySaveThreadState;
46 PyLockWrapper(PyThreadState* theThreadState);
53 std::string myComment;
55 ThreadLock(QMutex* theMutex, const char* theComment = "");
62 ThreadLock GetPyThreadLock(const char* theComment = "");
67 static PyThreadState *_gtstate;
70 static PyObject *builtinmodule;
71 static PyObject *salome_shared_modules_module;
76 virtual void initialize();
77 static void init_python();
79 int run(const char *command);
81 PyLockWrapper GetLockWrapper();
83 std::string getbanner();
84 std::string getverr();
85 std::string getvout();
87 const char * getPrevious();
88 const char * getNext();
91 PyThreadState * _tstate;
96 std::list<std::string> _history;
97 std::list<std::string>::iterator _ith;
100 int simpleRun(const char* command);
103 virtual void initState() = 0;
104 virtual void initContext() = 0;
111 PyObjWrapper(PyObject* theObject): myObject(theObject) {}
112 PyObjWrapper(): myObject(0) {}
113 operator PyObject*(){
116 PyObject* operator->(){
125 bool operator==(PyObject* theObject){
126 return myObject == theObject;
128 PyObject** operator&(){
131 PyObjWrapper& operator=(PyObjWrapper* theObjWrapper){
132 Py_XDECREF(myObject);
133 myObject = theObjWrapper->myObject;
136 virtual ~PyObjWrapper(){
137 Py_XDECREF(myObject);