Salome HOME
0023618: EDF 14415 - Plugins toolbar
authorvsr <vsr@opencascade.com>
Thu, 25 Oct 2018 13:00:22 +0000 (16:00 +0300)
committervsr <vsr@opencascade.com>
Tue, 20 Nov 2018 11:21:49 +0000 (14:21 +0300)
src/CAM/CAM_Module.cxx
src/CAM/CAM_Module.h
src/Qtx/QtxActionToolMgr.cxx
src/Qtx/QtxActionToolMgr.h
src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx
src/SALOME_PYQT/SalomePyQt/SalomePyQt.h
src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip
src/SUIT/SUIT_Application.cxx
src/SUIT/SUIT_Application.h
src/SalomeApp/salome_pluginsmanager.py

index fd814543e77538ce054bbbfc3e08f617c1d110c0..77877ea9782fda4354f9fdda89bae98bf2e6013c 100755 (executable)
@@ -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.
 
index 3cb43c1616f826df5d00b4d12278eb9418bb54b1..55451cb99c193642288e5651341630c574fadfb9 100755 (executable)
@@ -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 );
index deeb79355806307ff5645f8d400a50088cff41eb..3c47889c9d1c5ef4cd216ef20dc924654c927dd6 100644 (file)
@@ -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
index 4eaedbc6a78e00515629f12df5b616e5c5f32d32..833c83b0befc6fc2042478326d06cf84cdbfcf19 100644 (file)
@@ -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;
index 7466927b9ed60e1d329c2d4e4ddfb7d596ecc802..8590438e9c6216c532824bb7ebac6bf96542745e 100644 (file)
@@ -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();
   }
 };
 
index 843e639d8c4cf69ba4bddb50191c0784f1f3a971..2e691b596c643b1cc9823b5fc405fa11eeda21c8 100644 (file)
@@ -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 );
index 42d7f574b775b715df038804dfe72f2a99c483b3..8728843c08a09850e3796e52c44c3a0b6760e471 100644 (file)
@@ -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/ ;
index 06d9180ed8138cd4a388437a8f8014578d1d4de2..9216b5aa86b5173d64b4fa5f8c22530b66d03780 100644 (file)
@@ -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
index 3722c93d7645a29c58c0a009b0e3c928723848cb..f415e70cfea7caef4323edf13647dc8941ef14b3 100644 (file)
@@ -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 );//@}
index fefbe2c5fbdb40b3ca6de9996cb93e4d16b951aa..f17bab2c322bfc0e8002fc4fbb4754c1b2feaec1 100755 (executable)
@@ -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 """