1 // Copyright (C) 2007-2014 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
23 // File : PyInterp_Interp.h
24 // Author : Christian CAREMOLI, Paul RASCLE, Adrien BRUNETON
27 #ifndef PYINTERP_INTERP_H
28 #define PYINTERP_INTERP_H
30 #include "PyInterp.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
31 #include "PyInterp_Utils.h"
36 typedef void PyOutChanged(void* data,char * c);
47 * Main class representing a *virtual* Python interpreter. There is really only one true
48 * Python interpreter in the whole application (no call to Py_NewInterpreter),
49 * but the use of different execution contexts allow
50 * to split the execution lines, and hence to emulate (relatively) independent interpreters.
51 * This has some consequences: modules imported in one context are not re-imported in another context
52 * (only there namespace is made available when importing in another context).
53 * See also class PyConsole_Interp.
55 class PYINTERP_EXPORT PyInterp_Interp
62 virtual ~PyInterp_Interp();
67 virtual int run(const char *command);
68 virtual void initStudy(){};
70 // [ABN] - the PyLockWrapper is no more attached to the interpreter
71 // PyLockWrapper GetLockWrapper() const;
73 std::string getbanner() const;
74 void setverrcb(PyOutChanged*,void*);
75 void setvoutcb(PyOutChanged*,void*);
77 const char * getPrevious();
78 const char * getNext();
81 /** Redirection of stdout and stderr */
84 /** Execution context (local and global variables) */
85 PyObject * _global_context;
86 PyObject * _local_context;
88 std::list<std::string> _history;
89 std::list<std::string>::iterator _ith;
91 virtual int beforeRun();
92 virtual int afterRun();
93 int simpleRun(const char* command, const bool addToHistory = true);
95 virtual void initPython();
97 /** Initialize execution context. */
98 virtual bool initContext();
99 virtual bool initRun();
100 virtual void closeContext();
103 #endif // PYINTERP_INTERP_H