Back to index

salome-gui  6.5.0
Public Member Functions | Public Attributes
salome_pluginsmanager.PluginsManager Class Reference

List of all members.

Public Member Functions

def __init__
def analyseFile
def AddFunction
def importPlugins
def updateMenu

Public Attributes

 name
 basemenuname
 menuname
 module
 registry
 handlers
 entries
 lasttime
 plugindirs
 plugins_files
 basemenu
 menu

Detailed Description

Definition at line 149 of file salome_pluginsmanager.py.


Constructor & Destructor Documentation

def salome_pluginsmanager.PluginsManager.__init__ (   self,
  module,
  name,
  basemenuname,
  menuname 
)

Definition at line 150 of file salome_pluginsmanager.py.

00150 
00151     def __init__(self,module,name,basemenuname,menuname):
00152         self.name=name
00153         self.basemenuname=basemenuname
00154         self.menuname=menuname
00155         self.module=module
00156         self.registry={}
00157         self.handlers={}
00158         self.entries=[]
00159         self.lasttime=0
00160         self.plugindirs=[]
00161         self.plugins_files=[]
00162 
00163         # MODULES plugins directory.
00164         # The SALOME modules may provides natively some plugins. These
00165         # MODULES plugins are supposed to be located in the
00166         # installation folder of the module, in the subdirectory
00167         # "share/salome/plugins". We first look for these directories.
00168         for key in os.environ.keys():
00169           if key.endswith("_ROOT_DIR"):
00170             rootpath=os.environ[key]
00171             dirpath=os.path.join(rootpath,PLUGIN_PATH_PATTERN)
00172             if os.path.isdir(dirpath) and dirpath not in self.plugindirs:
00173               logger.debug("Looking for plugins in the directory %s ..."%dirpath)
00174               walktree(dirpath,self.analyseFile)
00175 
00176         # USER plugins directory
00177         user_dir = os.path.expanduser("~/.config/salome/Plugins")
00178         self.plugindirs.append(user_dir)
00179         logger.info("The user directory %s has been added to plugin paths"%user_dir)
00180         # obsolete: USER plugins directory
00181         # (for compatibility reasons only; new plugins should be stored in ~/.config/salome/Plugins)
00182         user_obsolete_dir = os.path.expanduser("~/.salome/Plugins")
00183         self.plugindirs.append(user_obsolete_dir)
00184         logger.info("The user directory %s has been added to plugin paths (deprecated)"%user_obsolete_dir)
00185 
00186         # APPLI plugins directory
00187         appli=os.getenv("APPLI")
00188         if appli:
00189           appli_dir=os.path.join(os.path.expanduser("~"),appli,"Plugins")
00190           self.plugindirs.append(appli_dir)
00191           logger.info("The APPLI directory %s has been added to plugin paths"%appli_dir)
00192 
00193         #SALOME_PLUGINS_PATH environment variable (list of directories separated by ":")
00194         pluginspath=os.getenv("SALOME_PLUGINS_PATH")
00195         if pluginspath:
00196           for directory in pluginspath.split(SEP):
00197             self.plugindirs.append(directory)
00198             logger.info("The directory %s has been added to plugin paths"%directory)
00199 
00200         self.basemenu = find_menu(self.basemenuname)
00201 
00202         if self.module:
00203           self.menu=QtGui.QMenu(self.menuname)
00204           mid=sgPyQt.createMenu(self.menu.menuAction(),self.basemenuname)
00205         else:
00206           self.menu=QtGui.QMenu(self.menuname,self.basemenu)
00207           self.basemenu.addMenu(self.menu)
00208 
00209         self.menu.menuAction().setVisible(False)
00210 
00211         self.basemenu.connect(self.basemenu, QtCore.SIGNAL("aboutToShow()"), self.importPlugins)


Member Function Documentation

def salome_pluginsmanager.PluginsManager.AddFunction (   self,
  name,
  description,
  script 
)
Add a plugin function

Definition at line 225 of file salome_pluginsmanager.py.

00225 
00226     def AddFunction(self,name,description,script):
00227         """ Add a plugin function
00228         """
00229         self.registry[name]=script,description
00230         self.entries.append(name)
00231 
00232         def handler(obj=self,script=script):
00233           try:
00234             script(Context(sgPyQt))
00235           except:
00236             s=traceback.format_exc()
00237             QtGui.QMessageBox.warning(None,"Exception occured",s)
00238 
00239         self.handlers[name]=handler

def salome_pluginsmanager.PluginsManager.analyseFile (   self,
  filename 
)
This function checks if the specified file is a plugins python
module and add the directory name of this file to the list of
plugin paths. This function is aimed to be used as the callback
function of the walktree algorithm.

Definition at line 212 of file salome_pluginsmanager.py.

00212 
00213     def analyseFile(self,filename):
00214       """
00215       This function checks if the specified file is a plugins python
00216       module and add the directory name of this file to the list of
00217       plugin paths. This function is aimed to be used as the callback
00218       function of the walktree algorithm.
00219       """
00220       if str(filename).endswith(MATCH_ENDING_PATTERN):
00221         dirpath=os.path.dirname(filename)
00222         if dirpath not in self.plugindirs:
00223           self.plugindirs.append(dirpath)
00224           logger.debug("The directory %s has been added to plugin paths"%dirpath)
        
Execute the salome_plugins file that contains plugins definition 

Definition at line 240 of file salome_pluginsmanager.py.

00240 
00241     def importPlugins(self):
00242         """Execute the salome_plugins file that contains plugins definition """
00243         studyId=sg.getActiveStudyId()
00244         if studyId == 0:
00245           self.menu.clear()
00246           self.menu.menuAction().setVisible(False)
00247           return
00248         elif self.lasttime ==0:
00249           salome.salome_init(embedded=1)
00250 
00251         lasttime=0
00252 
00253         plugins_files=[]
00254         plugins_file_name=self.name+MATCH_ENDING_PATTERN
00255         for directory in self.plugindirs:
00256           plugins_file = os.path.join(directory,plugins_file_name)
00257           if os.path.isfile(plugins_file):
00258             plugins_files.append((directory,plugins_file))
00259             lasttime=max(lasttime,os.path.getmtime(plugins_file))
00260 
00261         plugins_files.sort()
00262 
00263         if not plugins_files:
00264           self.registry.clear()
00265           self.handlers.clear()
00266           self.entries=[]
00267           self.lasttime=0
00268           self.menu.clear()
00269           self.menu.menuAction().setVisible(False)
00270           return
00271 
00272         if self.plugins_files != plugins_files or lasttime > self.lasttime:
00273           global current_plugins_manager
00274           current_plugins_manager=self
00275           self.registry.clear()
00276           self.handlers.clear()
00277           self.entries=[]
00278           self.lasttime=lasttime
00279           for directory,plugins_file in plugins_files:
00280             if directory not in sys.path:
00281               sys.path.insert(0,directory)
00282             try:
00283               execfile(plugins_file,globals(),{})
00284             except:
00285               logger.fatal("Error while loading plugins from file %s"%plugins_file)
00286               traceback.print_exc()
00287 
00288           self.updateMenu()

Here is the call graph for this function:

Update the Plugins menu

Definition at line 289 of file salome_pluginsmanager.py.

00289 
00290     def updateMenu(self):
00291         """Update the Plugins menu"""
00292         self.menu.clear()
00293         for entry in self.entries:
00294           names=entry.split("/")
00295           if len(names) < 1:continue
00296           parentMenu=self.menu
00297 
00298           if len(names) > 1:
00299             #create or get submenus
00300             submenus={}
00301             for action in parentMenu.actions():
00302               menu=action.menu()
00303               if menu:
00304                 submenus[str(menu.title())]=menu
00305             while len(names) > 1:
00306               name=names.pop(0)
00307               if submenus.has_key(name):
00308                 amenu=submenus[name]
00309               else:
00310                 amenu=QtGui.QMenu(name,parentMenu)
00311                 parentMenu.addMenu(amenu)
00312                 submenus[name]=amenu
00313               parentMenu=amenu
00314 
00315           name=names.pop(0)
00316           act=parentMenu.addAction(name,self.handlers[entry])
00317           act.setStatusTip(self.registry[entry][1])
00318 
00319         self.menu.menuAction().setVisible(True)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 199 of file salome_pluginsmanager.py.

Definition at line 152 of file salome_pluginsmanager.py.

Definition at line 157 of file salome_pluginsmanager.py.

Definition at line 156 of file salome_pluginsmanager.py.

Definition at line 158 of file salome_pluginsmanager.py.

Definition at line 202 of file salome_pluginsmanager.py.

Definition at line 153 of file salome_pluginsmanager.py.

Definition at line 154 of file salome_pluginsmanager.py.

Definition at line 151 of file salome_pluginsmanager.py.

Definition at line 159 of file salome_pluginsmanager.py.

Definition at line 160 of file salome_pluginsmanager.py.

Definition at line 155 of file salome_pluginsmanager.py.


The documentation for this class was generated from the following file: