1 // Copyright (C) 2007-2008 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.
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 : SALOME_PYQT_PyInterp.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "SALOME_PYQT_PyInterp.h" // this include must be first (see PyInterp_base.h)!
26 #include <utilities.h>
27 #include <Container_init_python.hxx>
30 * constructor : the main SALOME Python interpreter is used for PyQt GUI.
31 * calls initialize method defined in base class, which calls virtual methods
32 * initstate & initcontext redefined here
34 SALOME_PYQT_PyInterp::SALOME_PYQT_PyInterp(): PyInterp_Interp()
38 SALOME_PYQT_PyInterp::~SALOME_PYQT_PyInterp()
42 bool SALOME_PYQT_PyInterp::initState()
45 * The GIL is assumed to not be held on the call
46 * The GIL is acquired in initState and will be held on initState exit
47 * It is the caller responsability to release the lock on exit if needed
49 SCRUTE(KERNEL_PYTHON::_gtstate);
50 _tstate = KERNEL_PYTHON::_gtstate;
51 PyEval_AcquireThread(_tstate);
53 PyEval_ReleaseThread(_tstate);
57 bool SALOME_PYQT_PyInterp::initContext()
60 * The GIL is assumed to be held
61 * It is the caller responsability to acquire the GIL before calling initContext
62 * It will still be held on initContext exit
64 _g = PyDict_New(); // create interpreter dictionnary context
65 PyObject *bimod = PyImport_ImportModule("__builtin__");
66 PyDict_SetItemString(_g, "__builtins__", bimod);
71 int SALOME_PYQT_PyInterp::run(const char *command)
74 PyObject *code = Py_CompileString((char *)command,"PyGUI",Py_file_input);
76 // Une erreur s est produite en general SyntaxError
80 //#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0
81 // PyObject *r = PyEval_EvalCode(code,_g,_g);
83 PyObject *r = PyEval_EvalCode((PyCodeObject *)code,_g,_g);
87 // Une erreur s est produite a l execution