From: jfa Date: Wed, 14 Dec 2005 14:56:49 +0000 (+0000) Subject: Join modifications from branch BR_V3_1_0a3_Python X-Git-Tag: T_3_1_0pre~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=619dd688f7c8451f04f78665c6309e842539855b;p=modules%2Fgui.git Join modifications from branch BR_V3_1_0a3_Python --- diff --git a/doc/salome/GUI_index.html b/doc/salome/GUI_index.html new file mode 100755 index 000000000..465e3ea9d --- /dev/null +++ b/doc/salome/GUI_index.html @@ -0,0 +1,95 @@ + + + + + + + + Gui Module Documentation + + + +
  +
+
                   +   
+ + + + + + + + + +
+ + + +
+ +
+
+
+

GUI MODULE Documentation

+
+
+ + + + + +
+
+ +
+

Application-About.png +     

+
+ +
+ + + + +
+
+
+
+
+ +
+ +
GUI Documentation
+ +
+ +
+ +

+
+ +
+ +
TUI Documentation
+ +
+ +
+ +

+
+
+
+
+
+
+ + diff --git a/src/PyInterp/PyInterp_Dispatcher.cxx b/src/PyInterp/PyInterp_Dispatcher.cxx index 3312e527c..3d5067dba 100755 --- a/src/PyInterp/PyInterp_Dispatcher.cxx +++ b/src/PyInterp/PyInterp_Dispatcher.cxx @@ -31,7 +31,8 @@ void PyInterp_Request::process() safeExecute(); myMutex.lock(); - if ( !IsSync() && getListener() && getEvent() ) + //if ( !IsSync() && getListener() && getEvent() ) + if ( getListener() && getEvent() ) postEvent(); myMutex.unlock(); } @@ -56,7 +57,8 @@ QEvent* PyInterp_Request::createEvent() const QEvent* PyInterp_Request::getEvent() { - if ( !myEvent && !IsSync() ) + //if ( !myEvent && !IsSync() ) + if ( !myEvent ) myEvent = createEvent(); return myEvent; } @@ -142,7 +144,8 @@ void PyInterp_Dispatcher::Exec( PyInterp_Request* theRequest ) if ( !theRequest ) return; - if ( theRequest->IsSync() && !IsBusy() ) // synchronous processing - nothing is done if dispatcher is busy! + //if ( theRequest->IsSync() && !IsBusy() ) // synchronous processing - nothing is done if dispatcher is busy! + if ( theRequest->IsSync() ) // synchronous processing - nothing is done if dispatcher is busy! processRequest( theRequest ); else { // asynchronous processing myQueueMutex.lock(); diff --git a/src/PyInterp/PyInterp_base.cxx b/src/PyInterp/PyInterp_base.cxx index a75c39bdd..69ccefc9d 100644 --- a/src/PyInterp/PyInterp_base.cxx +++ b/src/PyInterp/PyInterp_base.cxx @@ -22,18 +22,30 @@ PyLockWrapper::PyLockWrapper(PyThreadState* theThreadState): myThreadState(theThreadState), mySaveThreadState(0) { - PyEval_AcquireLock(); - mySaveThreadState = PyThreadState_Swap(myThreadState); // store previous current in save, - // set local in current +#if defined(USE_GILSTATE) + if (myThreadState->interp == PyInterp_base::_interp) { + _savestate = PyGILState_Ensure(); + } else { + PyEval_AcquireThread(myThreadState); + } +#else + PyEval_AcquireThread(myThreadState); +#endif } - -PyLockWrapper::~PyLockWrapper(){ - PyThreadState_Swap(mySaveThreadState); // restore previous current (no need to get local, - PyEval_ReleaseLock(); // local thread state* already in _tstate +PyLockWrapper::~PyLockWrapper() +{ +#if defined(USE_GILSTATE) + if (myThreadState->interp == PyInterp_base::_interp) { + PyGILState_Release(_savestate); + } else { + PyEval_ReleaseThread(myThreadState); + } +#else + PyEval_ReleaseThread(myThreadState); +#endif } - class PyReleaseLock{ public: ~PyReleaseLock(){ @@ -47,14 +59,16 @@ PyLockWrapper PyInterp_base::GetLockWrapper(){ } -// main python interpreter +// main python interpreter (static attributes) -//PyThreadState *PyInterp_base::_gtstate = 0; // force 0 before execution int PyInterp_base::_argc = 1; char* PyInterp_base::_argv[] = {""}; PyObject *PyInterp_base::builtinmodule = NULL; +PyThreadState *PyInterp_base::_gtstate = NULL; +PyInterpreterState *PyInterp_base::_interp = NULL; + /*! * basic constructor here : herited classes constructors must call initalize() method @@ -66,8 +80,6 @@ PyInterp_base::PyInterp_base(): _tstate(0), _vout(0), _verr(0), _g(0), _atFirst( PyInterp_base::~PyInterp_base() { - PyLockWrapper aLock(_tstate); - //Py_EndInterpreter(_tstate); } @@ -85,10 +97,10 @@ void PyInterp_base::initialize() init_python(); // Here the global lock is released - // The lock will be acquired in initState. Make provision to release it on exit - PyReleaseLock aReleaseLock; - initState(); + + PyLockWrapper aLock= GetLockWrapper(); + initContext(); // used to interpret & compile commands @@ -96,45 +108,40 @@ void PyInterp_base::initialize() if(!m){ PyErr_Print(); return; - } - + } + // Create cStringIO to capture stdout and stderr PycString_IMPORT; - //PycStringIO = (PycStringIO_CAPI *)xxxPyCObject_Import("cStringIO", "cStringIO_CAPI"); _vout = PycStringIO->NewOutput(128); _verr = PycStringIO->NewOutput(128); - + // All the initRun outputs are redirected to the standard output (console) initRun(); } void PyInterp_base::init_python() { - static PyThreadState *_gtstate = 0; - _atFirst = false; if (Py_IsInitialized()) return; + // Python is not initialized Py_SetProgramName(_argv[0]); Py_Initialize(); // Initialize the interpreter PySys_SetArgv(_argc, _argv); PyEval_InitThreads(); // Create (and acquire) the interpreter lock + _interp = PyThreadState_Get()->interp; _gtstate = PyEval_SaveThread(); // Release global thread state -// if(!_gtstate){ -// PyReleaseLock aReleaseLock; -// Py_Initialize(); // Initialize the interpreter -// PyEval_InitThreads(); // Initialize and acquire the global interpreter lock -// PySys_SetArgv(_argc,_argv); // initialize sys.argv -// _gtstate = PyThreadState_Get(); -// } } string PyInterp_base::getbanner() { + // Should we take the lock ? + // PyEval_RestoreThread(_tstate); string aBanner("Python "); aBanner = aBanner + Py_GetVersion() + " on " + Py_GetPlatform() ; aBanner = aBanner + "\ntype help to get general information on environment\n"; + //PyEval_SaveThread(); return aBanner; } @@ -185,11 +192,11 @@ int compile_command(const char *command,PyObject *context) return 1; }else{ // Complete and correct text. We evaluate it. -#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0 - PyObjWrapper r(PyEval_EvalCode(v,context,context)); -#else + //#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0 + // PyObjWrapper r(PyEval_EvalCode(v,context,context)); + //#else PyObjWrapper r(PyEval_EvalCode((PyCodeObject *)(void *)v,context,context)); -#endif + //#endif if(!r){ // Execution error. We return -1 PyErr_Print(); @@ -240,15 +247,16 @@ int PyInterp_base::simpleRun(const char *command) // Reset redirected outputs before treatment PySys_SetObject("stderr",_verr); PySys_SetObject("stdout",_vout); - + PyObjWrapper verr(PyObject_CallMethod(_verr,"reset","")); PyObjWrapper vout(PyObject_CallMethod(_vout,"reset","")); - + int ier = compile_command(command,_g); // Outputs are redirected on standards outputs (console) PySys_SetObject("stdout",PySys_GetObject("__stdout__")); PySys_SetObject("stderr",PySys_GetObject("__stderr__")); + return ier; } @@ -290,4 +298,3 @@ string PyInterp_base::getvout(){ string aRet(PyString_AsString(v)); return aRet; } - diff --git a/src/PyInterp/PyInterp_base.h b/src/PyInterp/PyInterp_base.h index b2e0a0b26..66847770d 100644 --- a/src/PyInterp/PyInterp_base.h +++ b/src/PyInterp/PyInterp_base.h @@ -23,9 +23,16 @@ //#include // must be before Python.h ! #include // must be before qt includes ... +#include // Python include needed for versions before 2.4. Included in Python.h now. +#include // Python include needed for versions before 2.4. Included in Python.h now. -#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0 -extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l); +//#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0 +//extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l); +//#endif + +/* For 2.3, use the PyGILState_ calls */ +#if (PY_VERSION_HEX >= 0x02030000) +#define USE_GILSTATE #endif #define TOP_HISTORY_PY "--- top of history ---" @@ -35,17 +42,21 @@ class PYINTERP_EXPORT PyLockWrapper { PyThreadState* myThreadState; PyThreadState* mySaveThreadState; +#if defined(USE_GILSTATE) + PyGILState_STATE _savestate ; +#endif public: PyLockWrapper(PyThreadState* theThreadState); ~PyLockWrapper(); }; - class PYINTERP_EXPORT PyInterp_base{ public: static int _argc; static char* _argv[]; static PyObject *builtinmodule; + static PyThreadState *_gtstate; + static PyInterpreterState *_interp; PyInterp_base(); ~PyInterp_base(); diff --git a/src/PythonConsole/PythonConsole_PyEditor.cxx b/src/PythonConsole/PythonConsole_PyEditor.cxx index 0a5a4f0da..5bb4aed68 100755 --- a/src/PythonConsole/PythonConsole_PyEditor.cxx +++ b/src/PythonConsole/PythonConsole_PyEditor.cxx @@ -56,8 +56,10 @@ static QString DOTS_PROMPT = "... "; class ExecCommand : public PyInterp_LockRequest { public: - ExecCommand(PyInterp_base* theInterp, const char* theCommand, PythonConsole_PyEditor* theListener) -: PyInterp_LockRequest( theInterp, theListener ), myCommand(theCommand), myState( PyInterp_Event::OK ) + ExecCommand(PyInterp_base* theInterp, const char* theCommand, + PythonConsole_PyEditor* theListener, bool sync = false) + : PyInterp_LockRequest( theInterp, theListener, sync ), + myCommand( theCommand ), myState( PyInterp_Event::OK ) {} protected: diff --git a/src/PythonConsole/PythonConsole_PyInterp.cxx b/src/PythonConsole/PythonConsole_PyInterp.cxx index 62b483905..5b7d3e579 100755 --- a/src/PythonConsole/PythonConsole_PyInterp.cxx +++ b/src/PythonConsole/PythonConsole_PyInterp.cxx @@ -92,6 +92,7 @@ bool PythonConsole_PyInterp::initState() _tstate->interp->builtins = PyModule_GetDict(builtinmodule); Py_INCREF(_tstate->interp->builtins); } + PyEval_ReleaseThread(_tstate); return true; } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx index 055df7904..3cb6cbbda 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -503,11 +503,11 @@ void SALOME_PYQT_Module::init( CAM_Application* app ) PyLockWrapper aLock = myInterp->GetLockWrapper(); // ... (the Python module is already imported) // ... finally call Python module's initialize() method - PyObjWrapper res( PyObject_CallMethod( myModule, "initialize", "" ) ); - if( !res ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + if(PyObject_HasAttrString(myModule , "initialize")){ + PyObjWrapper res( PyObject_CallMethod( myModule, "initialize", "" ) ); + if( !res ) { + PyErr_Print(); + } } // get the windows list from the Python module by calling windows() method @@ -517,51 +517,51 @@ void SALOME_PYQT_Module::init( CAM_Application* app ) // VSR: LogWindow is not yet implemented // myWindowsMap.insert( SalomeApp_Application::WT_LogWindow, Qt::DockBottom ); - PyObjWrapper res1( PyObject_CallMethod( myModule, "windows", "" ) ); - if( !res1 ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); - } - else { - myWindowsMap.clear(); - if ( PyDict_Check( res1 ) ) { - PyObject* key; - PyObject* value; - int pos = 0; - while ( PyDict_Next( res1, &pos, &key, &value ) ) { - // parse the return value - // it should be a map: {integer:integer} - int aKey, aValue; - if( key && PyInt_Check( key ) && value && PyInt_Check( value ) ) { - aKey = PyInt_AsLong( key ); - aValue = PyInt_AsLong( value ); - myWindowsMap[ aKey ] = aValue; - } + if(PyObject_HasAttrString(myModule , "windows")){ + PyObjWrapper res1( PyObject_CallMethod( myModule, "windows", "" ) ); + if( !res1 ) { + PyErr_Print(); + } + else { + myWindowsMap.clear(); + if ( PyDict_Check( res1 ) ) { + PyObject* key; + PyObject* value; + int pos = 0; + while ( PyDict_Next( res1, &pos, &key, &value ) ) { + // parse the return value + // it should be a map: {integer:integer} + int aKey, aValue; + if( key && PyInt_Check( key ) && value && PyInt_Check( value ) ) { + aKey = PyInt_AsLong( key ); + aValue = PyInt_AsLong( value ); + myWindowsMap[ aKey ] = aValue; + } + } } } } // get the windows list from the Python module by calling views() method - PyObjWrapper res2( PyObject_CallMethod( myModule, "views", "" ) ); - if( !res2 ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); - } - else { - // parse the return value - // result can be one string... - if ( PyString_Check( res2 ) ) { - myViewMgrList.append( PyString_AsString( res2 ) ); + if(PyObject_HasAttrString(myModule , "views")){ + PyObjWrapper res2( PyObject_CallMethod( myModule, "views", "" ) ); + if( !res2 ) { + PyErr_Print(); } - // ... or list of strings - else if ( PyList_Check( res2 ) ) { - int size = PyList_Size( res2 ); - for ( int i = 0; i < size; i++ ) { - PyObject* value = PyList_GetItem( res2, i ); - if( value && PyString_Check( value ) ) { - myViewMgrList.append( PyString_AsString( value ) ); - } + else { + // parse the return value + // result can be one string... + if ( PyString_Check( res2 ) ) { + myViewMgrList.append( PyString_AsString( res2 ) ); + } + // ... or list of strings + else if ( PyList_Check( res2 ) ) { + int size = PyList_Size( res2 ); + for ( int i = 0; i < size; i++ ) { + PyObject* value = PyList_GetItem( res2, i ); + if( value && PyString_Check( value ) ) { + myViewMgrList.append( PyString_AsString( value ) ); + } + } } } } @@ -596,20 +596,20 @@ void SALOME_PYQT_Module::activate( SUIT_Study* theStudy ) if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__ // call Python module's setSettings() method (obsolete) - PyObjWrapper res( PyObject_CallMethod( myModule, "setSettings", "" ) ); - if( !res ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + if(PyObject_HasAttrString(myModule , "setSettings")){ + PyObjWrapper res( PyObject_CallMethod( myModule, "setSettings", "" ) ); + if( !res ) { + PyErr_Print(); + } } } //__CALL_OLD_METHODS__ // call Python module's activate() method (for the new modules) - PyObjWrapper res1( PyObject_CallMethod( myModule, "activate", "" ) ); - if( !res1 ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + if(PyObject_HasAttrString(myModule , "activate")){ + PyObjWrapper res1( PyObject_CallMethod( myModule, "activate", "" ) ); + if( !res1 ) { + PyErr_Print(); + } } } @@ -625,11 +625,11 @@ void SALOME_PYQT_Module::deactivate( SUIT_Study* theStudy ) return; } // then call Python module's deactivate() method - PyObjWrapper res( PyObject_CallMethod( myModule, "deactivate", "" ) ); - if( !res ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + if(PyObject_HasAttrString(myModule , "deactivate")){ + PyObjWrapper res( PyObject_CallMethod( myModule, "deactivate", "" ) ); + if( !res ) { + PyErr_Print(); + } } } @@ -659,11 +659,11 @@ void SALOME_PYQT_Module::studyChanged( SUIT_Study* theStudy ) PyLockWrapper aLock = myInterp->GetLockWrapper(); // call Python module's activeStudyChanged() method - PyObjWrapper res( PyObject_CallMethod( myModule, "activeStudyChanged", "i", aStudyId ) ); - if( !res ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + if(PyObject_HasAttrString(myModule , "activeStudyChanged")){ + PyObjWrapper res( PyObject_CallMethod( myModule, "activeStudyChanged", "i", aStudyId ) ); + if( !res ) { + PyErr_Print(); + } } } @@ -741,8 +741,8 @@ void SALOME_PYQT_Module::contextMenu( const QString& theContext, QPopupMenu* the return; QString aContext( theContext ), aObject( "" ), aParent( "" ); - - if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__ + + if ( IsCallOldMethods && PyObject_HasAttrString(myModule , "definePopup") ) { //__CALL_OLD_METHODS__ // call definePopup() Python module's function // this is obsolete function, used only for compatibility reasons PyObjWrapper res(PyObject_CallMethod( myModule, @@ -752,9 +752,7 @@ void SALOME_PYQT_Module::contextMenu( const QString& theContext, QPopupMenu* the aObject.latin1(), aParent.latin1() ) ); if( !res ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + PyErr_Print(); } else { // parse return value @@ -775,18 +773,18 @@ void SALOME_PYQT_Module::contextMenu( const QString& theContext, QPopupMenu* the PyObjWrapper sipPopup( sipBuildResult( 0, "M", thePopupMenu, sipClass_QPopupMenu ) ); // then call Python module's createPopupMenu() method (for new modules) - PyObjWrapper res1( PyObject_CallMethod( myModule, + if ( PyObject_HasAttrString(myModule , "createPopupMenu") ) { + PyObjWrapper res1( PyObject_CallMethod( myModule, "createPopupMenu", "Os", sipPopup.get(), aContext.latin1() ) ); - if( !res1 ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + if( !res1 ) { + PyErr_Print(); + } } - if ( IsCallOldMethods ) { //__CALL_OLD_METHODS__ + if ( IsCallOldMethods && PyObject_HasAttrString(myModule , "customPopup") ) { //__CALL_OLD_METHODS__ // call customPopup() Python module's function // this is obsolete function, used only for compatibility reasons PyObjWrapper res2( PyObject_CallMethod( myModule, @@ -797,9 +795,7 @@ void SALOME_PYQT_Module::contextMenu( const QString& theContext, QPopupMenu* the aObject.latin1(), aParent.latin1() ) ); if( !res2 ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + PyErr_Print(); } } //__CALL_OLD_METHODS__ } @@ -815,11 +811,11 @@ void SALOME_PYQT_Module::guiEvent( const int theId ) if ( !myInterp || !myModule ) return; - PyObjWrapper res( PyObject_CallMethod( myModule, "OnGUIEvent", "i", theId ) ); - if( !res ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + if ( PyObject_HasAttrString(myModule , "OnGUIEvent") ) { + PyObjWrapper res( PyObject_CallMethod( myModule, "OnGUIEvent", "i", theId ) ); + if( !res ) { + PyErr_Print(); + } } } @@ -934,11 +930,11 @@ void SALOME_PYQT_Module::setWorkSpace() } PyObjWrapper pyws( sipBuildResult( 0, "M", aWorkspace, sipClass_QWidget ) ); // ... and finally call Python module's setWorkspace() method (obsolete) - PyObjWrapper res( PyObject_CallMethod( myModule, "setWorkSpace", "O", pyws.get() ) ); - if( !res ) { - // VSR: this method may not be implemented in Python module - // PyErr_Print(); - PyErr_Clear(); + if ( PyObject_HasAttrString(myModule , "setWorkSpace") ) { + PyObjWrapper res( PyObject_CallMethod( myModule, "setWorkSpace", "O", pyws.get() ) ); + if( !res ) { + PyErr_Print(); + } } } //__CALL_OLD_METHODS__ } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.cxx index dbde7b1d3..1956ec3af 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_PyInterp.cxx @@ -38,9 +38,9 @@ bool SALOME_PYQT_PyInterp::initState() */ SCRUTE(KERNEL_PYTHON::_gtstate); _tstate = KERNEL_PYTHON::_gtstate; - PyEval_AcquireLock(); - PyThreadState_Swap(_tstate); + PyEval_AcquireThread(_tstate); SCRUTE(_tstate); + PyEval_ReleaseThread(_tstate); return true; } @@ -67,11 +67,11 @@ int SALOME_PYQT_PyInterp::run(const char *command) PyErr_Print(); return -1; } -#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0 - PyObject *r = PyEval_EvalCode(code,_g,_g); -#else - PyObject *r = PyEval_EvalCode((PyCodeObject*)code,_g,_g); -#endif + //#if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0 + // PyObject *r = PyEval_EvalCode(code,_g,_g); + //#else + PyObject *r = PyEval_EvalCode((PyCodeObject *)code,_g,_g); + //#endif Py_DECREF(code); if(!r){ // Une erreur s est produite a l execution @@ -81,4 +81,3 @@ int SALOME_PYQT_PyInterp::run(const char *command) Py_DECREF(r); return 0; } - diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip index eee54b26c..f306399b1 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip @@ -73,7 +73,7 @@ public: static const QString getActiveComponent(); static void updateObjBrowser( const int = 0, bool = true ); - static QString getFileName ( QWidget*, const QString&, const QStringList&, const QString&, bool ); + static QString getFileName ( QWidget*, const QString&, const QStringList&, const QString&, bool ) /ReleaseGIL/ ; static QStringList getOpenFileNames ( QWidget*, const QString&, const QStringList&, const QString& ); static QString getExistingDirectory( QWidget*, const QString&, const QString& ); diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 41b86354d..80f3080e5 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -80,7 +80,8 @@ SalomeApp_Application::SalomeApp_Application() */ SalomeApp_Application::~SalomeApp_Application() { - SalomeApp_EventFilter::Destroy(); + // Do not destroy. It's a singleton ! + //SalomeApp_EventFilter::Destroy(); } /*!Start application.*/ @@ -549,7 +550,8 @@ QString SalomeApp_Application::getFileFilter() const /*!Create window.*/ QWidget* SalomeApp_Application::createWindow( const int flag ) { - QWidget* wid = LightApp_Application::createWindow(flag); + QWidget* wid = 0; + if ( flag != WT_PyConsole ) wid = LightApp_Application::createWindow(flag); SUIT_ResourceMgr* resMgr = resourceMgr(); @@ -571,13 +573,11 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) } else if ( flag == WT_PyConsole ) { - delete wid; - wid = 0; PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() ); pyCons->setCaption( tr( "PYTHON_CONSOLE" ) ); wid = pyCons; pyCons->resize( pyCons->width(), desktop()->height()/4 ); - // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + //pyCons->connectPopupRequest(this, SLOT(onConnectPopupRequest(SUIT_PopupClient*, QContextMenuEvent*))); } return wid; } diff --git a/src/SalomeApp/SalomeApp_PyInterp.cxx b/src/SalomeApp/SalomeApp_PyInterp.cxx index a6549f646..19bc57559 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.cxx +++ b/src/SalomeApp/SalomeApp_PyInterp.cxx @@ -37,6 +37,7 @@ #include "PyInterp_base.h" // this include must be first (see PyInterp_base.h)! #include +using namespace std; /*! * constructor : multi Python interpreter, one per SALOME study. @@ -56,7 +57,7 @@ SalomeApp_PyInterp::~SalomeApp_PyInterp() /*!\class SalomeApp_PyInterp * EDF-CCAR - * Wasashen SALOME uses multi Python interpreter feature, + * When SALOME uses multi Python interpreter feature, * Every study has its own interpreter and thread state (_tstate = Py_NewInterpreter()) * This is fine because every study has its own modules (sys.modules) stdout and stderr * BUT some Python modules must be imported only once. In multi interpreter context Python @@ -83,14 +84,12 @@ bool SalomeApp_PyInterp::initContext() if ( !PythonConsole_PyInterp::initContext() ) return false; - // Debut modif CCAR // Import special module to change the import mechanism PyObjWrapper m1( PyImport_ImportModule( "import_hook" ) ); if ( !m1 ) { MESSAGE( "initContext: problem with import_hook import" ); PyErr_Print(); - PyErr_Clear(); ASSERT( 0 ); return false; } @@ -100,10 +99,9 @@ bool SalomeApp_PyInterp::initContext() PyObjWrapper m2( PyObject_CallMethod( m1, "init_shared_modules", "O", KERNEL_PYTHON::salome_shared_modules_module ) ); if ( !m2 ) { - MESSAGE( "initContext: problem with init_shared_modules call" ); - PyErr_Print(); - PyErr_Clear(); - ASSERT( 0 ); + MESSAGE( "initContext: problem with init_shared_modules call" ); + PyErr_Print(); + ASSERT( 0 ); return false; } @@ -113,19 +111,13 @@ bool SalomeApp_PyInterp::initContext() void SalomeApp_PyInterp::init_python() { /* - * Initialize the main state (_gtstate) if not already done - * The lock is released on init_python output - * It is the caller responsability to acquire it if needed + * Do nothing + * The initialization has been done in main */ MESSAGE("PyInterp_base::init_python"); ASSERT(KERNEL_PYTHON::_gtstate); // initialisation in main SCRUTE(KERNEL_PYTHON::_gtstate); -// if(!_gtstate){ -// PyReleaseLock aReleaseLock; -// Py_Initialize(); // Initialize the interpreter -// PyEval_InitThreads(); // Initialize and acquire the global interpreter lock -// PySys_SetArgv(_argc,_argv); // initialize sys.argv -// _gtstate = PyThreadState_Get(); -// } + _gtstate=KERNEL_PYTHON::_gtstate; + _interp=KERNEL_PYTHON::_interp; } diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index b6d432064..ac7738582 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -295,7 +295,6 @@ int main( int argc, char **argv ) { INFOS( "salome_shared_modules_module == NULL" ); PyErr_Print(); - PyErr_Clear(); } PyEval_ReleaseThread( KERNEL_PYTHON::_gtstate );