Salome HOME
Merge remote-tracking branch 'origin/V8_3_BR' into ngr/python3_dev
[modules/gui.git] / src / SALOME_PYQT / SALOME_PYQT_GUILight / SALOME_PYQT_PyInterp.cxx
index ab58c83d468cf8bde289bc543e71cb456c5ffa13..7bf7118531160b641a3f7b00ccdbb8a5e9f80817 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -52,6 +52,10 @@ void SALOME_PYQT_PyInterp::initPython()
   MESSAGE("SALOME_PYQT_PyInterp::initPython - does nothing");
 }
 
+/*!
+ * Override. Create a distinct context from the SALOME Python console.
+ * Especially the global context is not connected to __main__ as in PyInterp_Interp
+ */
 bool SALOME_PYQT_PyInterp::initContext()
 {
   /*
@@ -59,7 +63,8 @@ bool SALOME_PYQT_PyInterp::initContext()
    * It is the caller responsability to acquire the GIL before calling initContext
    * It will still be held on initContext exit
    */
-  _context = PyDict_New();          // create interpreter dictionnary context
+  _local_context = PyDict_New();
+  _global_context = PyDict_New();
   return true;
 }
 
@@ -72,7 +77,7 @@ int SALOME_PYQT_PyInterp::run(const char *command)
     PyErr_Print();
     return -1;
   }
-  PyObject *r = PyEval_EvalCode((PyCodeObject *)code,_context,_context);
+  PyObject *r = PyEval_EvalCode((PyObject *)code,_global_context,_local_context);
 
   Py_DECREF(code);
   if(!r){