Salome HOME
Fix problem in salome_test.py caused by recent replacement of pointe.med file
[modules/kernel.git] / src / KERNEL_PY / salome_iapp.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 #  This library is free software; you can redistribute it and/or
8 #  modify it under the terms of the GNU Lesser General Public
9 #  License as published by the Free Software Foundation; either
10 #  version 2.1 of the License.
11 #
12 #  This library is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  Lesser General Public License for more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public
18 #  License along with this library; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 #  File   : salome_iapp.py
24 #  Author : Paul RASCLE, EDF
25 #  Module : SALOME
26 #  $Header$
27 #
28 ## @package salome_iapp
29 # Module salome gives access to Salome GUI ressources (if GUI has been launched).
30 #
31
32 import salome_ComponentGUI
33
34     #--------------------------------------------------------------------------
35
36 IN_SALOME_GUI=0
37
38 def ImportComponentGUI(ComponentName):
39     if IN_SALOME_GUI:
40         libName = "lib" + ComponentName + "_Swig"
41         command = "from " + libName + " import *"
42         exec ( command )
43         constructor = ComponentName + "_Swig()"
44         command = "gui = " + constructor
45         exec ( command )
46         return gui
47     else:
48         print "Warning: ImportComponentGUI(",ComponentName,") outside GUI !"
49         print "calls to GUI methods may crash..."
50         return salome_ComponentGUI
51
52     #--------------------------------------------------------------------------
53
54 def SalomeGUIgetAllSelected(self):
55     selNumber = self.SelectedCount()
56     listSelected = []
57     for i in range(selNumber):
58         listSelected.append(self.getSelected(i))
59     return listSelected
60
61     #--------------------------------------------------------------------------
62
63 def hasDesktop():
64     return IN_SALOME_GUI
65
66     #--------------------------------------------------------------------------
67
68 salome_iapp_initial = 1
69
70 class SalomeOutsideGUI(object):
71     """
72     Provides a replacement for class SalomeGUI outside GUI process.
73     Do almost nothing
74     """
75     global myStudyId, myStudyName
76     
77     def hasDesktop(self):
78         """Indicate if GUI is running"""
79         return False
80     
81     def updateObjBrowser(self, bid):
82         """update the GUI object browser"""
83         print "SalomeOutsideGUI: no objectBrowser update outside GUI"
84         pass
85     
86     def getActiveStudyId(self):
87         """Get the active study id"""
88         print "SalomeOutsideGUI.getActiveStudyId: avoid use outside GUI"
89         return myStudyId
90     
91     def getActiveStudyName(self):
92         """Get the active study name"""
93         print "SalomeOutsideGUI.getActiveStudyName: avoid use outside GUI"
94         return myStudyName
95     
96     def SelectedCount(self):
97         """Get the number of active selections"""
98         print "SalomeOutsideGUI: no selection mecanism available outside GUI"
99         return 0
100     
101     def getSelected(self, i):
102         """Get the selection number i """
103         print "SalomeOutsideGUI: no selection mecanism available outside GUI"
104         return none
105     
106     def AddIObject(self, Entry):
107         """Add an entry"""
108         print "SalomeOutsideGUI.AddIOObject: not available outside GUI"
109         pass
110     
111     def RemoveIObject(self, Entry):
112         """Remove an entry"""
113         print "SalomeOutsideGUI.REmoveIOObject: not available outside GUI"
114         pass
115     
116     def ClearIObjects(self):
117         """Clear entries"""
118         print "SalomeOutsideGUI.ClearIOObject: not available outside GUI"
119         pass
120     
121     def Display(self, Entry):
122         """Display an entry"""
123         print "SalomeOutsideGUI.Display: not available outside GUI"
124         pass
125     
126     def DisplayOnly(self, Entry):
127         """Display only an entry"""
128         print "SalomeOutsideGUI.DisplayOnly: not available outside GUI"
129         pass
130     
131     def Erase(self, Entry):
132         """Erase en entry"""
133         print "SalomeOutsideGUI.Erase: not available outside GUI"
134         pass
135     
136     def DisplayAll(self):
137         """Display all"""
138         print "SalomeOutsideGUI.Erase: not available outside GUI"
139         pass
140     
141     def EraseAll(self):
142         """Erase all"""
143         print "SalomeOutsideGUI.EraseAll: not available outside GUI"
144         pass
145
146     def IsInCurrentView(self, Entry):
147         """Indicate if an entry is in current view"""
148         print "SalomeOutsideGUI.IsIncurentView: not available outside GUI"
149         return False
150         
151     def getComponentName(self, ComponentUserName ):
152         """Get component name from component user name"""
153         print "SalomeOutsideGUI.getComponentName: not available outside GUI"
154         return ""
155    
156     def getComponentUserName( self, ComponentName ):
157         """Get component user name from component name"""
158         print "SalomeOutsideGUI.getComponentUserName: not available outside GUI"
159         return ""
160         
161     #--------------------------------------------------------------------------
162
163     
164 def salome_iapp_init(embedded):
165     global salome_iapp_initial
166     global sg,IN_SALOME_GUI
167
168     if salome_iapp_initial:
169         salome_iapp_initial=0
170         if embedded:
171             import libSALOME_Swig
172         
173             class SalomeGUI(libSALOME_Swig.SALOMEGUI_Swig):
174                 getAllSelected = SalomeGUIgetAllSelected
175
176             # create a SALOMEGUI_Swig instance
177             sg = SalomeGUI()
178             IN_SALOME_GUI = sg.hasDesktop()
179         else:
180             # Not embedded in GUI
181             sg=SalomeOutsideGUI()
182             IN_SALOME_GUI=0
183     return sg