Salome HOME
Merge remote-tracking branch 'origin/V8_3_BR' into ngr/python3_dev
[modules/gui.git] / src / SalomeApp / SalomeApp_PyInterp.cxx
index e79c8361320ee59144b9e24e8b788871890e92c7..4db5aff1a717e351f4c332d6114620250fde117d 100755 (executable)
@@ -28,7 +28,7 @@
   \brief Constructor
 */
 SalomeApp_PyInterp::SalomeApp_PyInterp()
-  : PyConsole_Interp(), myFirstRun( true ), myFirstInitStudy( false )
+  : myFirstRun( true ), myFirstInitStudy( false )
 {
 }
 
@@ -39,6 +39,23 @@ SalomeApp_PyInterp::~SalomeApp_PyInterp()
 {
 }
  
+/*!
+ * Initialize context dictionaries. GIL is held already.
+ * The code executed in an embedded interpreter is expected to be run at the module
+ * level, in which case local and global context have to be the same dictionary.
+ * See: http://stackoverflow.com/questions/12265756/c-python-running-python-code-within-a-context
+ * for an explanation.
+ */
+bool SalomeApp_PyInterp::initContext()
+{
+  bool ok = PyConsole_Interp::initContext();
+  if ( ok ) {
+    int ret = PyRun_SimpleString( "import salome_iapp; salome_iapp.IN_SALOME_GUI = True" );
+    ok = ok && (ret == 0);
+  }
+  return ok;
+}
+
 /*!
   \brief Called before each Python command running.
 */