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"
34 typedef void PyOutChanged(void* data,char * c);
45 * Main class representing a *virtual* Python interpreter. There is really only one true
46 * Python interpreter in the whole application (no call to Py_NewInterpreter),
47 * but the use of different execution contexts allow
48 * to split the execution lines, and hence to emulate (relatively) independent interpreters.
49 * This has some consequences: modules imported in one context are not re-imported in another context
50 * (only there namespace is made available when importing in another context).
51 * See also class PyConsole_Interp.
53 class PYINTERP_EXPORT PyInterp_Interp
60 virtual ~PyInterp_Interp();
65 virtual int run(const char *command);
66 virtual void initStudy() {};
68 std::string getBanner() const;
69 void setverrcb(PyOutChanged*, void*);
70 void setvoutcb(PyOutChanged*, void*);
72 const char* getPrevious();
73 const char* getNext();
76 /** Redirection of stdout and stderr */
79 /** Execution context (local and global variables) */
80 PyObject* _global_context;
81 PyObject* _local_context;
83 std::list<std::string> _history;
84 std::list<std::string>::iterator _ith;
86 virtual int beforeRun();
87 virtual int afterRun();
88 int simpleRun(const char* command, const bool addToHistory = true);
90 virtual void initPython();
92 /** Initialize execution context. */
93 virtual bool initContext();
94 virtual bool initRun();
95 virtual void closeContext();
97 bool initialized() const;
103 #endif // PYINTERP_INTERP_H