Back to index

salome-kernel  6.5.0
salome_iapp.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  File   : salome_iapp.py
00025 #  Author : Paul RASCLE, EDF
00026 #  Module : SALOME
00027 #  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/KERNEL_PY/salome_iapp.py,v 1.6.2.3.14.2.12.1 2012-04-12 14:05:13 vsr Exp $
00028 ## @package salome_iapp
00029 # Module salome gives access to Salome GUI ressources (if GUI has been launched).
00030 #
00031 import salome_ComponentGUI
00032 
00033     #--------------------------------------------------------------------------
00034 
00035 IN_SALOME_GUI=0
00036 
00037 def ImportComponentGUI(ComponentName):
00038     if IN_SALOME_GUI:
00039         libName = "lib" + ComponentName + "_Swig"
00040         command = "from " + libName + " import *"
00041         exec ( command )
00042         constructor = ComponentName + "_Swig()"
00043         command = "gui = " + constructor
00044         exec ( command )
00045         return gui
00046     else:
00047         print "Warning: ImportComponentGUI(",ComponentName,") outside GUI !"
00048         print "calls to GUI methods may crash..."
00049         return salome_ComponentGUI
00050 
00051     #--------------------------------------------------------------------------
00052 
00053 def SalomeGUIgetAllSelected(self):
00054     selNumber = self.SelectedCount()
00055     listSelected = []
00056     for i in range(selNumber):
00057         listSelected.append(self.getSelected(i))
00058     return listSelected
00059 
00060     #--------------------------------------------------------------------------
00061 
00062 def hasDesktop():
00063     return IN_SALOME_GUI
00064 
00065     #--------------------------------------------------------------------------
00066 
00067 salome_iapp_initial = 1
00068 
00069 class SalomeOutsideGUI(object):
00070     """
00071     Provides a replacement for class SalomeGUI outside GUI process.
00072     Do almost nothing
00073     """
00074     global myStudyId, myStudyName
00075     
00076     def hasDesktop(self):
00077         """Indicate if GUI is running"""
00078         return False
00079     
00080     def updateObjBrowser(self, bid):
00081         """update the GUI object browser"""
00082         print "SalomeOutsideGUI: no objectBrowser update outside GUI"
00083         pass
00084     
00085     def getActiveStudyId(self):
00086         """Get the active study id"""
00087         print "SalomeOutsideGUI.getActiveStudyId: avoid use outside GUI"
00088         return myStudyId
00089     
00090     def getActiveStudyName(self):
00091         """Get the active study name"""
00092         print "SalomeOutsideGUI.getActiveStudyName: avoid use outside GUI"
00093         return myStudyName
00094     
00095     def SelectedCount(self):
00096         """Get the number of active selections"""
00097         print "SalomeOutsideGUI: no selection mecanism available outside GUI"
00098         return 0
00099     
00100     def getSelected(self, i):
00101         """Get the selection number i """
00102         print "SalomeOutsideGUI: no selection mecanism available outside GUI"
00103         return none
00104     
00105     def AddIObject(self, Entry):
00106         """Add an entry"""
00107         print "SalomeOutsideGUI.AddIOObject: not available outside GUI"
00108         pass
00109     
00110     def RemoveIObject(self, Entry):
00111         """Remove an entry"""
00112         print "SalomeOutsideGUI.REmoveIOObject: not available outside GUI"
00113         pass
00114     
00115     def ClearIObjects(self):
00116         """Clear entries"""
00117         print "SalomeOutsideGUI.ClearIOObject: not available outside GUI"
00118         pass
00119     
00120     def Display(self, Entry):
00121         """Display an entry"""
00122         print "SalomeOutsideGUI.Display: not available outside GUI"
00123         pass
00124     
00125     def DisplayOnly(self, Entry):
00126         """Display only an entry"""
00127         print "SalomeOutsideGUI.DisplayOnly: not available outside GUI"
00128         pass
00129     
00130     def Erase(self, Entry):
00131         """Erase en entry"""
00132         print "SalomeOutsideGUI.Erase: not available outside GUI"
00133         pass
00134     
00135     def DisplayAll(self):
00136         """Display all"""
00137         print "SalomeOutsideGUI.Erase: not available outside GUI"
00138         pass
00139     
00140     def EraseAll(self):
00141         """Erase all"""
00142         print "SalomeOutsideGUI.EraseAll: not available outside GUI"
00143         pass
00144 
00145     def IsInCurrentView(self, Entry):
00146         """Indicate if an entry is in current view"""
00147         print "SalomeOutsideGUI.IsIncurentView: not available outside GUI"
00148         return False
00149         
00150     def getComponentName(self, ComponentUserName ):
00151         """Get component name from component user name"""
00152         print "SalomeOutsideGUI.getComponentName: not available outside GUI"
00153         return ""
00154    
00155     def getComponentUserName( self, ComponentName ):
00156         """Get component user name from component name"""
00157         print "SalomeOutsideGUI.getComponentUserName: not available outside GUI"
00158         return ""
00159         
00160     #--------------------------------------------------------------------------
00161 
00162     
00163 def salome_iapp_init(embedded):
00164     global salome_iapp_initial
00165     global sg,IN_SALOME_GUI
00166 
00167     if salome_iapp_initial:
00168         salome_iapp_initial=0
00169         if embedded:
00170             import libSALOME_Swig
00171         
00172             class SalomeGUI(libSALOME_Swig.SALOMEGUI_Swig):
00173                 getAllSelected = SalomeGUIgetAllSelected
00174 
00175             # create a SALOMEGUI_Swig instance
00176             sg = SalomeGUI()
00177             IN_SALOME_GUI = sg.hasDesktop()
00178         else:
00179             # Not embedded in GUI
00180             sg=SalomeOutsideGUI()
00181             IN_SALOME_GUI=0
00182     return sg