From 380050e8391555a1381b61c43e8b09c512d47c41 Mon Sep 17 00:00:00 2001 From: caremoli Date: Mon, 29 Mar 2010 07:03:19 +0000 Subject: [PATCH] CCAR: modify createMenu in SalomePyQt to be able to add menus not only in a Python module but also in a C++ module --- src/LightApp/LightApp_Module.cxx | 27 +++++++++++++++++++++++ src/LightApp/LightApp_Module.h | 7 ++++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 11 +++++---- src/SalomeApp/salome_pluginsmanager.py | 6 ++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 228234513..761853695 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -649,3 +649,30 @@ bool LightApp_Module::reusableOperation( const int id ) { return true; } + + + +int LightApp_Module::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx ) +{ + return CAM_Module::createMenu( subMenu, menu, id, group, idx ); +} +int LightApp_Module::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx ) +{ + return CAM_Module::createMenu( subMenu, menu, id, group, idx ); +} +int LightApp_Module::createMenu( const int id, const int menu, const int group, const int idx ) +{ + return CAM_Module::createMenu( id, menu, group, idx ); +} +int LightApp_Module::createMenu( const int id, const QString& menu, const int group, const int idx ) +{ + return CAM_Module::createMenu( id, menu, group, idx ); +} +int LightApp_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx ) +{ + return CAM_Module::createMenu( a, menu, id, group, idx ); +} +int LightApp_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx ) +{ + return CAM_Module::createMenu( a, menu, id, group, idx ); +} diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index c608497e5..19c857f48 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -92,6 +92,13 @@ public: virtual LightApp_Displayer* displayer(); virtual LightApp_Selection* createSelection() const; + int createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 ); + int createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 ); + int createMenu( const int, const int, const int = -1, const int = -1 ); + int createMenu( const int, const QString&, const int = -1, const int = -1 ); + int createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 ); + int createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 ); + public slots: virtual bool activateModule( SUIT_Study* ); virtual bool deactivateModule( SUIT_Study* ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index b7efe52de..8c6c60537 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -1521,7 +1521,7 @@ public: CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx ) : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {} - int execute( SALOME_PYQT_ModuleLight* module ) const + int execute( LightApp_Module* module ) const { if ( module ) { switch ( myCase ) { @@ -1562,9 +1562,12 @@ public: : myResult( -1 ), myCrMenu( crMenu ) {} virtual void Execute() { - SALOME_PYQT_ModuleLight* module = getActiveModule(); - if ( module ) - myResult = myCrMenu.execute( module ); + if ( LightApp_Application* anApp = getApplication() ) + { + LightApp_Module* module = dynamic_cast( anApp->activeModule() ); + if ( module ) + myResult = myCrMenu.execute( module ); + } } }; diff --git a/src/SalomeApp/salome_pluginsmanager.py b/src/SalomeApp/salome_pluginsmanager.py index 6dfb9f29c..0b566b9bd 100644 --- a/src/SalomeApp/salome_pluginsmanager.py +++ b/src/SalomeApp/salome_pluginsmanager.py @@ -133,7 +133,11 @@ class Plugins: for directory,salome_plugins_file in plugins_files: if directory not in sys.path: sys.path.insert(0,directory) - execfile(salome_plugins_file,globals(),{}) + try: + execfile(salome_plugins_file,globals(),{}) + except: + print "Error while loading plugins from file:",salome_plugins_file + traceback.print_exc() self.updateMenu() def updateMenu(self): -- 2.39.2