1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOME_PYQT_PyInterp.cxx
8 // Author : Christian CAREMOLI, Paul RASCLE, EDF
12 #include "SALOME_PYQT_PyInterp.h" // this include must be first (see PyInterp_base.h)!
13 #include "utilities.h"
14 #include "Container_init_python.hxx"
20 * constructor : the main SALOME Python interpreter is used for PyQt GUI.
21 * calls initialize method defined in base class, which calls virtual methods
22 * initstate & initcontext redefined here
24 SALOME_PYQT_PyInterp::SALOME_PYQT_PyInterp(): PyInterp_base()
28 SALOME_PYQT_PyInterp::~SALOME_PYQT_PyInterp()
32 bool SALOME_PYQT_PyInterp::initState()
35 * The GIL is assumed to not be held on the call
36 * The GIL is acquired in initState and will be held on initState exit
37 * It is the caller responsability to release the lock on exit if needed
39 SCRUTE(KERNEL_PYTHON::_gtstate);
40 _tstate = KERNEL_PYTHON::_gtstate;
42 PyThreadState_Swap(_tstate);
47 bool SALOME_PYQT_PyInterp::initContext()
50 * The GIL is assumed to be held
51 * It is the caller responsability to acquire the GIL before calling initContext
52 * It will still be held on initContext exit
54 _g = PyDict_New(); // create interpreter dictionnary context
55 PyObject *bimod = PyImport_ImportModule("__builtin__");
56 PyDict_SetItemString(_g, "__builtins__", bimod);
61 int SALOME_PYQT_PyInterp::run(const char *command)
64 PyObject *code = Py_CompileString((char *)command,"PyGUI",Py_file_input);
66 // Une erreur s est produite en general SyntaxError
70 PyObject *r = PyEval_EvalCode(code,_g,_g);
73 // Une erreur s est produite a l execution