From: vsr Date: Thu, 25 Oct 2018 13:00:22 +0000 (+0300) Subject: 0023618: EDF 14415 - Plugins toolbar X-Git-Tag: V9_3_0a1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=45f02f5b9c6a3f4017f789a23740009aa562b021;p=modules%2Fgui.git 0023618: EDF 14415 - Plugins toolbar --- diff --git a/src/CAM/CAM_Module.cxx b/src/CAM/CAM_Module.cxx index fd814543e..77877ea97 100755 --- a/src/CAM/CAM_Module.cxx +++ b/src/CAM/CAM_Module.cxx @@ -599,6 +599,16 @@ int CAM_Module::createTool( const int id, const QString& tBar, const int idx ) return intId != -1 ? id : -1; } +/*! + Clears given toolbar. + \param title - title of toolbar +*/ +void CAM_Module::clearTool( const QString& title ) +{ + if ( toolMgr() ) + toolMgr()->clear( title ); +} + /*! \brief Create menu or submenu. diff --git a/src/CAM/CAM_Module.h b/src/CAM/CAM_Module.h index 3cb43c161..55451cb99 100755 --- a/src/CAM/CAM_Module.h +++ b/src/CAM/CAM_Module.h @@ -113,6 +113,7 @@ public: int createTool( const int, const QString&, const int = -1 ); int createTool( QAction*, const int, const int = -1, const int = -1 ); int createTool( QAction*, const QString&, const int = -1, const int = -1 ); + void clearTool( const QString& title ); int createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1,QMenu * = 0); int createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 ); diff --git a/src/Qtx/QtxActionToolMgr.cxx b/src/Qtx/QtxActionToolMgr.cxx index deeb79355..3c47889c9 100644 --- a/src/Qtx/QtxActionToolMgr.cxx +++ b/src/Qtx/QtxActionToolMgr.cxx @@ -442,6 +442,29 @@ void QtxActionToolMgr::remove( const int id, const QString& title ) remove( id, find( title ) ); } +/*! + \brief Remove all actions from toolbar. + \param tid toolbar ID +*/ +void QtxActionToolMgr::clear( const int tid ) +{ + if ( !myToolBars.contains( tid ) ) + return; + + myToolBars[tid].nodes.clear(); + + triggerUpdate( tid ); +} + +/*! + \brief Remove all actions from toolbar. + \param title toolbar title +*/ +void QtxActionToolMgr::clear( const QString& title ) +{ + clear( find( title ) ); +} + /*! \brief Get toolbar by given \a tid. \param tid toolbar ID diff --git a/src/Qtx/QtxActionToolMgr.h b/src/Qtx/QtxActionToolMgr.h index 4eaedbc6a..833c83b0b 100644 --- a/src/Qtx/QtxActionToolMgr.h +++ b/src/Qtx/QtxActionToolMgr.h @@ -99,6 +99,8 @@ public: void remove( const int, const int ); void remove( const int, const QString& ); + void clear( const int ); + void clear( const QString& ); QToolBar* toolBar( const int ) const; QToolBar* toolBar( const QString& ) const; diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 7466927b9..8590438e9 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -2050,21 +2050,34 @@ public: CrTool( QAction* action, const QString& tBar, const int id, const int idx ) : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {} - int execute( LightApp_Module* module ) const + int execute() const { - if ( module ) { - switch ( myCase ) { - case 0: - return module->createTool( myTbTitle, myTbName ); - case 1: - return module->createTool( myId, myTbId, myIndex ); - case 2: - return module->createTool( myId, myTbTitle, myIndex ); - case 3: - return module->createTool( myAction, myTbId, myId, myIndex ); - case 4: - return module->createTool( myAction, myTbTitle, myId, myIndex ); - } + switch ( myCase ) { + case 0: + if ( getActiveModule() ) + return getActiveModule()->createTool( myTbTitle, myTbName ); + else if ( getApplication() ) + return getApplication()->createTool( myTbTitle, myTbName ); + case 1: + if ( getActiveModule() ) + return getActiveModule()->createTool( myId, myTbId, myIndex ); + else if ( getApplication() ) + return getApplication()->createTool( myId, myTbId, myIndex ); + case 2: + if ( getActiveModule() ) + return getActiveModule()->createTool( myId, myTbTitle, myIndex ); + else if ( getApplication() ) + return getApplication()->createTool( myId, myTbTitle, myIndex ); + case 3: + if ( getActiveModule() ) + return getActiveModule()->createTool( myAction, myTbId, myId, myIndex ); + else if ( getApplication() ) + return getApplication()->createTool( myAction, myTbId, myId, myIndex ); + case 4: + if ( getActiveModule() ) + return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex ); + else if ( getApplication() ) + return getApplication()->createTool( myAction, myTbTitle, myId, myIndex ); } return -1; } @@ -2088,9 +2101,7 @@ public: : myResult( -1 ), myCrTool( crTool ) {} virtual void Execute() { - LightApp_Module* module = getActiveModule(); - if ( module ) - myResult = myCrTool.execute( module ); + myResult = myCrTool.execute(); } }; @@ -2142,6 +2153,30 @@ int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) ); } + +/*! + \brief Clear given toolbar. + \param title toolbar's title +*/ +void SalomePyQt::clearTool( const QString& title ) +{ + class TEvent: public SALOME_Event + { + QString myTitle; + public: + TEvent( const QString& title ) + : myTitle( title ) {} + virtual void Execute() + { + if ( getActiveModule() ) + return getActiveModule()->clearTool( myTitle ); + else if ( getApplication() ) + return getApplication()->clearTool( myTitle ); + } + }; + ProcessVoidEvent( new TEvent( title ) ); +} + /*! \brief Insert action to the toolbar. \param a action @@ -2171,23 +2206,39 @@ 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( LightApp_Module* module ) const + int execute() const { - if ( module ) { - switch ( myCase ) { - case 0: - return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex ); - case 1: - return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex ); - case 2: - return module->createMenu( myId, myMenuId, myGroup, myIndex ); - case 3: - return module->createMenu( myId, myMenuName, myGroup, myIndex ); - case 4: - return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex ); - case 5: - return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex ); - } + switch ( myCase ) { + case 0: + if ( getActiveModule() ) + return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex ); + else if ( getApplication() ) + return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex ); + case 1: + if ( getActiveModule() ) + return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex ); + else if ( getApplication() ) + return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex ); + case 2: + if ( getActiveModule() ) + return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex ); + else if ( getApplication() ) + return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex ); + case 3: + if ( getActiveModule() ) + return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex ); + else if ( getApplication() ) + return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex ); + case 4: + if ( getActiveModule() ) + return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex ); + else if ( getApplication() ) + return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex ); + case 5: + if ( getActiveModule() ) + return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex ); + else if ( getApplication() ) + return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex ); } return -1; } @@ -2212,9 +2263,7 @@ public: : myResult( -1 ), myCrMenu( crMenu ) {} virtual void Execute() { - LightApp_Module* module = getActiveModule(); - if ( module ) - myResult = myCrMenu.execute( module ); + myResult = myCrMenu.execute(); } }; diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 843e639d8..2e691b596 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -245,6 +245,7 @@ public: static int createTool( const int, const QString&, const int = -1 ); static int createTool( QAction*, const int, const int = -1, const int = -1 ); static int createTool( QAction*, const QString&, const int = -1, const int = -1 ); + static void clearTool( const QString& ); static int createMenu( const QString&, const int = -1, const int = -1, const int = -1, const int = -1 ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 42d7f574b..8728843c0 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -359,6 +359,7 @@ public: static int createTool( const int, const QString&, const int = -1 ) /ReleaseGIL/ ; static int createTool( QAction*, const int, const int = -1, const int = -1 ) /ReleaseGIL/ ; static int createTool( QAction*, const QString&, const int = -1, const int = -1 ) /ReleaseGIL/ ; + static void clearTool( const QString& ) /ReleaseGIL/ ; static int createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 ) /ReleaseGIL/ ; diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index 06d9180ed..9216b5aa8 100644 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -399,6 +399,16 @@ int SUIT_Application::createTool( const int id, const QString& tBar, const int i return intId != -1 ? id : -1; } +/*! + Clears given toolbar. + \param title - title of toolbar +*/ +void SUIT_Application::clearTool( const QString& title ) +{ + if ( desktop() && desktop()->toolMgr() ) + desktop()->toolMgr()->clear( title ); +} + /*! Creates new menu item \return identificator of new action in menu manager diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 3722c93d7..f415e70cf 100644 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -118,6 +118,22 @@ public: void addPostRoutine( void (*theRoutine)() ); + /** @name Create tool functions*/ //@{ + int createTool( const QString&, const QString& = QString() ); + int createTool( const int, const int, const int = -1 ); + int createTool( const int, const QString&, const int = -1 ); + int createTool( QAction*, const int, const int = -1, const int = -1 ); + int createTool( QAction*, const QString&, const int = -1, const int = -1 );//@} + void clearTool( const QString& ); + + /** @name Create menu functions*/ //@{ + 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 );//@} + signals: void applicationClosed( SUIT_Application* ); void activated( SUIT_Application* ); @@ -141,21 +157,6 @@ protected: virtual SUIT_Study* createNewStudy(); virtual void setActiveStudy( SUIT_Study* ); - /** @name Create tool functions*/ //@{ - int createTool( const QString&, const QString& = QString() ); - int createTool( const int, const int, const int = -1 ); - int createTool( const int, const QString&, const int = -1 ); - int createTool( QAction*, const int, const int = -1, const int = -1 ); - int createTool( QAction*, const QString&, const int = -1, const int = -1 );//@} - - /** @name Create menu functions*/ //@{ - 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 );//@} - /** @name Set menu shown functions*/ //@{ void setMenuShown( QAction*, const bool ); void setMenuShown( const int, const bool );//@} diff --git a/src/SalomeApp/salome_pluginsmanager.py b/src/SalomeApp/salome_pluginsmanager.py index fefbe2c5f..f17bab2c3 100755 --- a/src/SalomeApp/salome_pluginsmanager.py +++ b/src/SalomeApp/salome_pluginsmanager.py @@ -156,6 +156,7 @@ class PluginsManager: self.lasttime=0 self.plugindirs=[] self.plugins_files=[] + self.toolbar = None # MODULES plugins directory. # The SALOME modules may provides natively some plugins. These @@ -205,11 +206,14 @@ class PluginsManager: else: self.menu=QMenu(self.menuname,self.basemenu) self.basemenu.addMenu(self.menu) + self.toolbar=sgPyQt.createTool(self.menuname) self.menu.menuAction().setVisible(False) self.basemenu.aboutToShow.connect(self.importPlugins) + self.importPlugins() # to create toolbar immediately + def analyseFile(self,filename): """ This function checks if the specified file is a plugins python @@ -223,10 +227,10 @@ class PluginsManager: self.plugindirs.append(dirpath) logger.debug("The directory %s has been added to plugin paths"%dirpath) - def AddFunction(self,name,description,script): + def AddFunction(self,name,description,script,icon=None): """ Add a plugin function """ - self.registry[name]=script,description + self.registry[name]=script,description,icon self.entries.append(name) def handler(obj=self,script=script): @@ -287,6 +291,7 @@ class PluginsManager: def updateMenu(self): """Update the Plugins menu""" self.menu.clear() + sgPyQt.clearTool(self.menuname) for entry in self.entries: names=entry.split("/") if len(names) < 1:continue @@ -312,14 +317,18 @@ class PluginsManager: name=names.pop(0) act=parentMenu.addAction(name,self.handlers[entry]) act.setStatusTip(self.registry[entry][1]) + icon = self.registry[entry][2] if len(self.registry[entry])>2 else None + if icon is not None and not icon.isNull() and icon.availableSizes(): + act.setIcon(icon) + sgPyQt.createTool(act, self.toolbar) self.menu.menuAction().setVisible(True) -def AddFunction(name,description,script): +def AddFunction(name,description,script,icon=None): """ Add a plugin function Called by a user to register a function (script) """ - return current_plugins_manager.AddFunction(name,description,script) + return current_plugins_manager.AddFunction(name,description,script,icon) def entries(): """ Return the list of entries in menu: can be sorted or modified in place to customize menu content """