Salome HOME
Updates from V7_dev branch
[modules/gui.git] / src / SalomeApp / salome_pluginsmanager.py
index 10bf174fd58f2c1516df8702721c7e0e32c10d4c..ba0dd119a8964f122df8a75841beeb608aef4ad6 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 
 """
 This module is imported from C++ SalomeApp_Application and initialized
-(call to initialize function with 4 parameters) module : 0 if it's
-plugins manager at the application level 1 if it is at the module
-level name : the name of the plugins manager. This name is used to
-build the name of the plugins files basemenuname : the name of the
-menu into we want to add the menu of the plugins ("Tools" for example)
-menuname : the name of plugins menu
+(call to initialize function with 4 parameters)
+module :       0 if it is plugins manager at the application level, 1 if it is at the module level
+name :         the name of the plugins manager. This name is used to build the name of the plugins files
+basemenuname : the name of the menu into we want to add the menu of the plugins ("Tools" for example)
+menuname :     the name of plugins menu
 
 A plugins manager is created when calling initialize.
 
@@ -44,7 +44,7 @@ name salome_plugins.py (example follows)::
   import salome_pluginsmanager
 
   def about(context):
-    from PyQt4.QtGui import QMessageBox
+    from qtsalome import QMessageBox
     QMessageBox.about(None, "About SALOME pluginmanager", "SALOME plugins manager in SALOME virtual application ")
 
   salome_pluginsmanager.AddFunction('About plugins','About SALOME pluginmanager',about)
@@ -54,8 +54,7 @@ AddFunction.  It is possible to customize this presentation by getting
 the entries list (salome_pluginsmanager.entries()) and modifying it in
 place. For example, you can do that :
 salome_pluginsmanager.entries().sort() to order them alphabetically or
-salome_pluginsmanager.entries().remove("a") to remove the entry named
-"a".
+salome_pluginsmanager.entries().remove("a") to remove the entry named "a".
 
 It is possible to put entries in submenus. You only need to give a
 name with / to the entry. for example::
@@ -84,8 +83,7 @@ context attributes:
 """
 
 import os,sys,traceback
-from PyQt4 import QtGui
-from PyQt4 import QtCore
+from qtsalome import *
 
 import salome
 
@@ -125,13 +123,15 @@ class Context:
 
 def find_menu(smenu):
   lmenus=smenu.split("|")
-  main=lmenus.takeFirst().trimmed()
+  # Take first element from the list
+  main=lmenus.pop(0).strip()
   menu=sgPyQt.getPopupMenu(main)
   return findMenu(lmenus,menu)
 
 def findMenu(lmenu,menu):
   if not lmenu:return menu
-  m=lmenu.takeFirst().trimmed()
+  # Take first element from the list
+  m=lmenu.pop(0).strip()
   for a in menu.actions():
     if a.menu():
       if a.text() == m:
@@ -149,8 +149,8 @@ logger=Logger("PluginsManager") #,color=GREEN)
 class PluginsManager:
     def __init__(self,module,name,basemenuname,menuname):
         self.name=name
-        self.basemenuname=QtCore.QString.fromUtf8(basemenuname)
-        self.menuname=QtCore.QString.fromUtf8(menuname)
+        self.basemenuname=unicode(basemenuname)
+        self.menuname=unicode(menuname)
         self.module=module
         self.registry={}
         self.handlers={}
@@ -199,15 +199,15 @@ class PluginsManager:
         self.basemenu = find_menu(self.basemenuname)
 
         if self.module:
-          self.menu=QtGui.QMenu(self.menuname)
+          self.menu=QMenu(self.menuname)
           mid=sgPyQt.createMenu(self.menu.menuAction(),self.basemenuname)
         else:
-          self.menu=QtGui.QMenu(self.menuname,self.basemenu)
+          self.menu=QMenu(self.menuname,self.basemenu)
           self.basemenu.addMenu(self.menu)
 
         self.menu.menuAction().setVisible(False)
 
-        self.basemenu.connect(self.basemenu, QtCore.SIGNAL("aboutToShow()"), self.importPlugins)
+        self.basemenu.aboutToShow.connect(self.importPlugins)
 
     def analyseFile(self,filename):
       """
@@ -233,7 +233,7 @@ class PluginsManager:
             script(Context(sgPyQt))
           except:
             s=traceback.format_exc()
-            QtGui.QMessageBox.warning(None,"Exception occured",s)
+            QMessageBox.warning(None,"Exception occured",s)
 
         self.handlers[name]=handler
 
@@ -276,8 +276,10 @@ class PluginsManager:
           self.entries=[]
           self.lasttime=lasttime
           for directory,plugins_file in plugins_files:
+            logger.debug("look for python path: %s"%directory)
             if directory not in sys.path:
               sys.path.insert(0,directory)
+              logger.debug("The directory %s has been added to PYTHONPATH"%directory)
             try:
               execfile(plugins_file,globals(),{})
             except:
@@ -306,7 +308,7 @@ class PluginsManager:
               if submenus.has_key(name):
                 amenu=submenus[name]
               else:
-                amenu=QtGui.QMenu(name,parentMenu)
+                amenu=QMenu(name,parentMenu)
                 parentMenu.addMenu(amenu)
                 submenus[name]=amenu
               parentMenu=amenu