Salome HOME
INT PAL 0052660: Plot2D Viewer: Plot2d_Curve can't be selected
[modules/gui.git] / src / PyInterp / PyInterp_Interp.cxx
index f76c3c69ef7d4f64b7a10e75368982a43567f641..48c6a8eb5b5a2e415f0d7a90e9031ce9f788a40d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -293,7 +293,10 @@ bool PyInterp_Interp::initContext()
   _global_context = PyModule_GetDict(m);          // get interpreter global variable context
   Py_INCREF(_global_context);
   _local_context = _global_context;
-  return true;
+
+  int ret = PyRun_SimpleString("import salome_iapp;salome_iapp.IN_SALOME_GUI=True");
+
+  return ret == 0;
 }
 
 /*!
@@ -412,7 +415,9 @@ static int compile_command(const char *command, PyObject * global_ctxt, PyObject
 int PyInterp_Interp::run(const char *command)
 {
   beforeRun();
-  return simpleRun(command);
+  int ret = simpleRun(command);
+  afterRun();
+  return ret;
 }
 
 /**
@@ -424,6 +429,15 @@ int PyInterp_Interp::beforeRun()
   return 0;
 }
 
+/**
+ * Called after a command is run (when calling run() method). Not thread-safe. Caller's responsability
+ * to acquire GIL if needed.
+ */
+int PyInterp_Interp::afterRun()
+{
+  return 0;
+}
+
 /*!
   \brief Run Python command (used internally). Not thread-safe. GIL acquisition is caller's responsability.
   \param command Python command