Creates new python interpreter.
*/
PyConsole_Interp::PyConsole_Interp(): PyInterp_Interp()
-{
-}
+{}
/*!
\brief Destructor.
Does nothing for the moment.
*/
-PyConsole_Interp::~PyConsole_Interp()
+PyConsole_Interp::~PyConsole_Interp() { }
+
+/*! Sets the variable "__IN_SALOME_GUI_CONSOLE" to True.
+* This is not attached to a module (like salome_iapp.IN_SALOME_GUI_CONSOLE)
+* since modules are shared across all interpreters in SALOME.
+*
+* (GIL is already acquired here)
+*/
+int PyConsole_Interp::beforeRun()
{
+ return PyRun_SimpleString("__builtins__.__IN_SALOME_GUI_CONSOLE=True");
}
+int PyConsole_Interp::afterRun()
+{
+ return PyRun_SimpleString("__builtins__.__IN_SALOME_GUI_CONSOLE=False");
+}
public:
PyConsole_Interp();
~PyConsole_Interp();
+
+ virtual int afterRun();
+ virtual int beforeRun();
};
#endif // PYCONSOLE_INTERP_H
_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;
}
/*!
int PyInterp_Interp::run(const char *command)
{
beforeRun();
- return simpleRun(command);
+ int ret = simpleRun(command);
+ afterRun();
+ return ret;
}
/**
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
std::list<std::string>::iterator _ith;
virtual int beforeRun();
+ virtual int afterRun();
int simpleRun(const char* command, const bool addToHistory = true);
virtual void initPython();