1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : PyInterp_Interp.h
23 // Author : Christian CAREMOLI, Paul RASCLE, Adrien BRUNETON
25 #ifndef PYINTERP_INTERP_H
26 #define PYINTERP_INTERP_H
28 #include "PyInterp.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
29 #include "PyInterp_Utils.h"
30 #include "PyInterp_RefCounterObj.h"
35 typedef void PyOutChanged(void* data,char * c);
46 * Main class representing a *virtual* Python interpreter. There is really only one true
47 * Python interpreter in the whole application (no call to Py_NewInterpreter),
48 * but the use of different execution contexts allow
49 * to split the execution lines, and hence to emulate (relatively) independent interpreters.
50 * This has some consequences: modules imported in one context are not re-imported in another context
51 * (only there namespace is made available when importing in another context).
52 * See also class PyConsole_Interp.
54 class PYINTERP_EXPORT PyInterp_Interp : public PyInterp_RefCounterObj
63 virtual int run(const char *command);
64 virtual void initStudy() {}
66 std::string getBanner() const;
67 void setverrcb(PyOutChanged*, void*);
68 void setvoutcb(PyOutChanged*, void*);
70 const char* getPrevious();
71 const char* getNext();
76 virtual ~PyInterp_Interp();
79 /** Redirection of stdout and stderr */
82 /** Execution context (local and global variables) */
83 PyObject* _global_context;
84 PyObject* _local_context;
86 std::list<std::string> _history;
87 std::list<std::string>::iterator _ith;
89 virtual int beforeRun();
90 virtual int afterRun();
91 int simpleRun(const char* command, const bool addToHistory = true);
93 virtual void initPython();
95 /** Initialize execution context. */
96 virtual bool initContext();
97 virtual bool initRun();
98 virtual void closeContext();
100 bool initialized() const;
106 #endif // PYINTERP_INTERP_H