From: vsr Date: Mon, 17 Mar 2014 08:59:19 +0000 (+0400) Subject: Fix single study problem in Python API X-Git-Tag: V7_4_0b1~2^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ad3a201cc2ac15f456e69b7b51a29b847b8eea4d;p=modules%2Fgui.git Fix single study problem in Python API - add methods to finalize current study - finalize study from GUI when it is closed or unloaded --- diff --git a/src/PyConsole/PyConsole_Editor.cxx b/src/PyConsole/PyConsole_Editor.cxx index 636ee54a7..4caf5e48b 100644 --- a/src/PyConsole/PyConsole_Editor.cxx +++ b/src/PyConsole/PyConsole_Editor.cxx @@ -190,6 +190,9 @@ PyConsole_Editor::PyConsole_Editor( PyConsole_Interp* theInterp, */ PyConsole_Editor::~PyConsole_Editor() { + myInterp->destroy(); + delete myInterp; + myInterp = 0; } /*! diff --git a/src/PyConsole/PyConsole_Interp.cxx b/src/PyConsole/PyConsole_Interp.cxx index 9d3d996ca..10e6fa0e6 100644 --- a/src/PyConsole/PyConsole_Interp.cxx +++ b/src/PyConsole/PyConsole_Interp.cxx @@ -77,6 +77,7 @@ bool PyConsole_Interp::initContext() PyErr_Print(); return false; } - _context = PyModule_GetDict(m); // get interpreter dictionnary context + PyObject* global_dict = PyModule_GetDict(m); // get interpreter dictionnary context + _context = PyDict_Copy(global_dict); return true; } diff --git a/src/PyInterp/PyInterp_Interp.cxx b/src/PyInterp/PyInterp_Interp.cxx index 0ee1e0173..f70141b6b 100644 --- a/src/PyInterp/PyInterp_Interp.cxx +++ b/src/PyInterp/PyInterp_Interp.cxx @@ -254,6 +254,12 @@ void PyInterp_Interp::initialize() initRun(); } +void PyInterp_Interp::destroy() +{ + PyLockWrapper lck; + closeContext(); +} + /*! \brief Initialize Python interpreter. @@ -302,6 +308,10 @@ bool PyInterp_Interp::initRun() return true; } +void PyInterp_Interp::closeContext() +{ +} + /*! \brief Compile Python command and evaluate it in the python dictionary context if possible. This is not thread-safe. diff --git a/src/PyInterp/PyInterp_Interp.h b/src/PyInterp/PyInterp_Interp.h index 55c2c7005..048bc448c 100644 --- a/src/PyInterp/PyInterp_Interp.h +++ b/src/PyInterp/PyInterp_Interp.h @@ -73,6 +73,7 @@ public: virtual ~PyInterp_Interp(); void initialize(); + void destroy(); virtual int run(const char *command); @@ -106,6 +107,7 @@ protected: /** Initialize execution context. Must set the member _context, and return True on success. */ virtual bool initContext() = 0; virtual bool initRun(); + virtual void closeContext(); }; /** diff --git a/src/SalomeApp/SalomeApp_PyInterp.cxx b/src/SalomeApp/SalomeApp_PyInterp.cxx index c2e329cc5..a8d89daa9 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.cxx +++ b/src/SalomeApp/SalomeApp_PyInterp.cxx @@ -77,3 +77,9 @@ int SalomeApp_PyInterp::beforeRun() } return true; } + +void SalomeApp_PyInterp::closeContext() +{ + simpleRun( "import salome", false ); + simpleRun( "salome.salome_close()", false ); +} diff --git a/src/SalomeApp/SalomeApp_PyInterp.h b/src/SalomeApp/SalomeApp_PyInterp.h index 801121239..ef556fcec 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.h +++ b/src/SalomeApp/SalomeApp_PyInterp.h @@ -36,6 +36,7 @@ public: virtual ~SalomeApp_PyInterp(); virtual void initPython(); + virtual void closeContext(); protected: virtual int beforeRun();