1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SALOME_PYQT_PyInterp.h" // this include must be first !!
22 #include <SUITApp_init_python.hxx>
23 #include <PyInterp_Interp.h>
24 #include <utilities.h>
26 #ifndef GUI_DISABLE_CORBA
27 #include <Container_init_python.hxx>
34 * constructor : the main SALOME Python interpreter is used for PyQt GUI.
35 * calls initialize method defined in base class, which calls virtual methods
36 * initstate & initcontext redefined here
38 SALOME_PYQT_PyInterp::SALOME_PYQT_PyInterp(): PyInterp_Interp()
42 SALOME_PYQT_PyInterp::~SALOME_PYQT_PyInterp()
46 void SALOME_PYQT_PyInterp::initPython()
50 * The initialization has been done in main
52 MESSAGE("SALOME_PYQT_PyInterp::initPython - does nothing");
56 * Override. Create a distinct context from the SALOME Python console.
57 * Especially the global context is not connected to __main__ as in PyInterp_Interp
59 bool SALOME_PYQT_PyInterp::initContext()
62 * The GIL is assumed to be held
63 * It is the caller responsability to acquire the GIL before calling initContext
64 * It will still be held on initContext exit
66 _local_context = PyDict_New();
67 _global_context = PyDict_New();
71 int SALOME_PYQT_PyInterp::run(const char *command)
74 PyObject *code = Py_CompileString((char *)command,"PyGUI",Py_file_input);
76 // An error occured - normally here a SyntaxError
80 PyObject *r = PyEval_EvalCode((PyObject *)code,_global_context,_local_context);
84 // An error occured at execution