From: vsv Date: Fri, 22 Nov 2013 12:06:21 +0000 (+0000) Subject: PPGP patch: provides "closeStudy" event X-Git-Tag: V7_3_0a1~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=75458e7ab6e5345b70f338764a757011230931ac;p=modules%2Fgui.git PPGP patch: provides "closeStudy" event --- diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index eb9437f05..886022377 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -162,7 +162,7 @@ bool SALOME_PYQT_ModuleLight::activateModule( SUIT_Study* study ) \sa PyModuleHelper::deactivate() */ bool SALOME_PYQT_ModuleLight::deactivateModule( SUIT_Study* study ) -{ +{ // call helper bool res = myHelper->deactivate( study ); @@ -170,6 +170,21 @@ bool SALOME_PYQT_ModuleLight::deactivateModule( SUIT_Study* study ) return LightApp_Module::deactivateModule( study ) && res; } +/*! + \brief Close of the module. + + This function is usually used in order to close the module's + specific menus and toolbars and perform other such actions + required when the module is closed. +*/ +void SALOME_PYQT_ModuleLight::onModelClosed() +{ + // call helper + myHelper->modelClosed(application()->activeStudy()); + LightApp_Module::onModelClosed(); +} + + /*! \brief Get the dockable windows associated with the module. \param winMap output map of dockable windows in form { : } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h index f6e7143df..dff9b5963 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h @@ -49,6 +49,7 @@ public: void initialize( CAM_Application* ); bool activateModule( SUIT_Study* ); bool deactivateModule( SUIT_Study* ); + void onModelClosed(); void windows( QMap& ) const; void viewManagers( QStringList& ) const; void studyActivated(); diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx index 25120ac5e..b4eba060a 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx @@ -962,6 +962,58 @@ bool PyModuleHelper::deactivate( SUIT_Study* study ) return true; } +/*! + \brief Close of the module. + + This function is usually used in order to close the module's + specific menus and toolbars and perform other such actions + required when the module is closed. +*/ +void PyModuleHelper::modelClosed( SUIT_Study* study ) +{ + FuncMsg fmsg( "PyModuleHelper::modelClosed()" ); + + class StudyClosedReq : public PyInterp_LockRequest + { + public: + StudyClosedReq( PyInterp_Interp* _py_interp, + PyModuleHelper* _helper, + SUIT_Study* _study ) + : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) + myHelper( _helper ), + myStudy ( _study ) + {} + protected: + virtual void execute() + { + myHelper->internalClosedStudy( myStudy ); + } + private: + PyModuleHelper* myHelper; + SUIT_Study* myStudy; + }; + + // post request + PyInterp_Dispatcher::Get()->Exec( new StudyClosedReq( myInterp, this, study ) ); + + // disconnect preferences changing signal + disconnect( myModule->getApp(), SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ), + this, SLOT( preferenceChanged( const QString&, const QString&, const QString& ) ) ); + + // disconnect the SUIT_Desktop signal windowActivated() + SUIT_Desktop* d = study->application()->desktop(); + disconnect( d, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( activeViewChanged( SUIT_ViewWindow* ) ) ); + + // deactivate menus, toolbars, etc + if ( myXmlHandler ) myXmlHandler->activateMenus( false ); + + // hide menus / toolbars + myModule->setMenuShown( false ); + myModule->setToolShown( false ); +} + + /*! \brief Process module's preferences changing. @@ -2013,6 +2065,39 @@ void PyModuleHelper::internalDeactivate( SUIT_Study* study ) } } +/*! + \brief Internal closure: + + Performs the following actions: + - call Python module's closeStudy() method + + \param theStudy parent study object +*/ +void PyModuleHelper::internalClosedStudy( SUIT_Study* theStudy ) +{ + FuncMsg fmsg( "--- PyModuleHelper::internalClosedStudy()" ); + + // Get study Id + // get study Id + LightApp_Study* aStudy = dynamic_cast( theStudy ); + int aStudyId = aStudy ? aStudy->id() : 0; + + // check that Python subinterpreter is initialized and Python module is imported + if ( !myInterp || !myPyModule ) { + // Error! Python subinterpreter should be initialized and module should be imported first! + return; + } + // then call Python module's deactivate() method + if ( PyObject_HasAttrString( myPyModule , (char*)"closeStudy" ) ) { + PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"closeStudy", (char*)"i", aStudyId ) ); + if( !res ) { + PyErr_Print(); + } + } +} + + + /*! \brief Preference changing callback function. \internal diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h index f450ab89a..49c429632 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h @@ -86,6 +86,7 @@ public slots: void initialize( CAM_Application* ); bool activate( SUIT_Study* study ); bool deactivate( SUIT_Study* study ); + void modelClosed( SUIT_Study* study ); void preferencesChanged( const QString&, const QString& setting ); void preferenceChanged( const QString&, const QString&, const QString& setting ); void studyActivated( SUIT_Study* ); @@ -114,6 +115,7 @@ private: void internalActivate( SUIT_Study* ); void internalCustomize( SUIT_Study* ); void internalDeactivate( SUIT_Study* ); + void internalClosedStudy( SUIT_Study* ); void internalPreferencesChanged( const QString&, const QString& ); void internalStudyChanged( SUIT_Study* ); void internalActionActivated( int );