From: vsr Date: Fri, 3 Nov 2006 11:16:55 +0000 (+0000) Subject: Improvement: add signal to allow customization of preferences changing processing X-Git-Tag: V3_2_3pre2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4754fa57915fb678ae4cd0d6ef23a435419b02d6;p=modules%2Fgui.git Improvement: add signal to allow customization of preferences changing processing --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 4ea110009..a99958e13 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1551,6 +1551,8 @@ void LightApp_Application::onPreferenceChanged( QString& modName, QString& secti sMod->preferencesChanged( section, param ); else preferencesChanged( section, param ); + // emit signal to allow additional preferences changing processing + emit preferenceChanged( modName, section, param ); } /*!Private SLOT. On open document with name \a aName.*/ diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index cec21a876..cf4a27b80 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -155,6 +155,7 @@ signals: void studyOpened(); void studySaved(); void studyClosed(); + void preferenceChanged( const QString&, const QString&, const QString& ); public slots: virtual void onHelpContentsModule(); 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 bbe4a419c..9e8cc8ca6 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -282,6 +282,8 @@ bool SALOME_PYQT_Module::activateModule( SUIT_Study* theStudy ) if ( menuMgr() ) connect( menuMgr(), SIGNAL( menuHighlighted( int, int ) ), this, SLOT( onMenuHighlighted( int, int ) ) ); + connect( getApp(), SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ), + this, SLOT( preferenceChanged( const QString&, const QString&, const QString& ) ) ); // create menus & toolbars from XML file if required if ( myXmlHandler ) @@ -325,6 +327,8 @@ bool SALOME_PYQT_Module::deactivateModule( SUIT_Study* theStudy ) if ( menuMgr() ) disconnect( menuMgr(), SIGNAL( menuHighlighted( int, int ) ), this, SLOT( onMenuHighlighted( int, int ) ) ); + disconnect( getApp(), SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ), + this, SLOT( preferenceChanged( const QString&, const QString&, const QString& ) ) ); // remove menus & toolbars created from XML file if required if ( myXmlHandler ) @@ -362,6 +366,49 @@ bool SALOME_PYQT_Module::deactivateModule( SUIT_Study* theStudy ) return SalomeApp_Module::deactivateModule( theStudy ); } +/*! + Preferences changing (application) - called when preference is changed +*/ +void SALOME_PYQT_Module::preferenceChanged( const QString& module, + const QString& section, + const QString& setting ) +{ + MESSAGE( "SALOME_PYQT_Module::preferenceChanged"); + + // perform synchronous request to Python event dispatcher + class Event : public PyInterp_LockRequest + { + public: + Event( PyInterp_base* _py_interp, + SALOME_PYQT_Module* _obj, + const QString& _section, + const QString& _setting ) + : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) + myObj ( _obj ), + mySection( _section ), + mySetting( _setting ) {} + + protected: + virtual void execute() + { + myObj->prefChanged( mySection, mySetting ); + } + + private: + SALOME_PYQT_Module* myObj; + QString mySection, mySetting; + }; + + if ( module != moduleName() ) { + // Module's preferences are processed by preferencesChanged() method + // ... + // Posting the request only if dispatcher is not busy! + // Executing the request synchronously + if ( !PyInterp_Dispatcher::Get()->IsBusy() ) + PyInterp_Dispatcher::Get()->Exec( new Event( myInterp, this, section, setting ) ); + } +} + /*! * Called when study desktop is activated. * Used for notifying about changing of the active study. @@ -545,7 +592,7 @@ void SALOME_PYQT_Module::contextMenuPopup( const QString& theContext, QPopupMenu */ void SALOME_PYQT_Module::createPreferences() { - MESSAGE( "SALOME_PYQT_Module::createPr eferences"); + MESSAGE( "SALOME_PYQT_Module::createPreferences"); // perform synchronous request to Python event dispatcher class Event : public PyInterp_LockRequest { @@ -599,6 +646,44 @@ void SALOME_PYQT_Module::viewManagers( QStringList& listik ) const } } +/*! + Preferences changing (module) - called when the module's preferences are changed +*/ +void SALOME_PYQT_Module::preferencesChanged( const QString& section, const QString& setting ) +{ + MESSAGE( "SALOME_PYQT_Module::preferencesChanged"); + + // perform synchronous request to Python event dispatcher + class Event : public PyInterp_LockRequest + { + public: + Event( PyInterp_base* _py_interp, + SALOME_PYQT_Module* _obj, + const QString& _section, + const QString& _setting ) + : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) + myObj ( _obj ), + mySection( _section ), + mySetting( _setting ) {} + + protected: + virtual void execute() + { + myObj->prefChanged( mySection, mySetting ); + } + + private: + SALOME_PYQT_Module* myObj; + QString mySection, mySetting; + }; + + // Posting the request only if dispatcher is not busy! + // Executing the request synchronously + if ( !PyInterp_Dispatcher::Get()->IsBusy() ) + PyInterp_Dispatcher::Get()->Exec( new Event( myInterp, this, section, setting ) ); +} + + /*! * Performs internal initialization * - initializes/gets the Python interpreter (one per study) @@ -1124,6 +1209,29 @@ void SALOME_PYQT_Module::setWorkSpace() } //__CALL_OLD_METHODS__ } +/*! + * Preference changing callback function + * - calls Python module's preferenceChanged(string,string,string) method + */ +void SALOME_PYQT_Module::prefChanged( const QString& section, const QString& setting ) +{ + // Python interpreter should be initialized and Python module should be + // import first + if ( !myInterp || !myModule ) + return; + + if ( PyObject_HasAttrString(myModule , "preferenceChanged") ) { + PyObjWrapper res( PyObject_CallMethod( myModule, + "preferenceChanged", + "ss", + section.latin1(), + setting.latin1() ) ); + if( !res ) { + PyErr_Print(); + } + } +} + /*! * Returns default menu group */ diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h index 8814e0b66..b8b9aeb90 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h @@ -163,12 +163,18 @@ public: void setMenuShown( const bool ); void setToolShown( const bool ); + /* Preferences changing (module) */ + void preferencesChanged( const QString&, const QString& ); + public slots: /* activation */ virtual bool activateModule( SUIT_Study* ); /* deactivation */ virtual bool deactivateModule( SUIT_Study* ); + /* Preferences changing (application) */ + void preferenceChanged( const QString&, const QString&, const QString& ); + /****************************** * Internal methods ******************************/ @@ -216,6 +222,9 @@ private: /* set workspace to Python GUI module */ void setWorkSpace(); + /* preferences changing */ + void prefChanged( const QString&, const QString& ); + friend class SALOME_PYQT_XmlHandler; };