Salome HOME
[EDF17049] : Porting to Python3
[modules/kernel.git] / src / KERNEL_PY / salome_iapp.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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, or (at your option) any later version.
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
24 #  File   : salome_iapp.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : SALOME
27 #  $Header$
28 ## @package salome_iapp
29 # Module salome gives access to Salome GUI resources (if GUI has been launched).
30 #
31 import salome_ComponentGUI
32
33     #--------------------------------------------------------------------------
34
35 IN_SALOME_GUI=None
36
37 def ImportComponentGUI(ComponentName):
38     if IN_SALOME_GUI:
39         libName = "lib" + ComponentName + "_Swig"
40         command = "from " + libName + " import *"
41         exec (command, globals())
42         constructor = ComponentName + "_Swig()"
43         command = "gui = " + constructor
44         exec (command, globals())
45         return gui  # @UndefinedVariable
46     else:
47         print("Warning: ImportComponentGUI(",ComponentName,") outside GUI !")
48         print("calls to GUI methods may crash...")
49         return salome_ComponentGUI
50
51     #--------------------------------------------------------------------------
52
53 def SalomeGUIgetAllSelected(self):
54     selNumber = self.SelectedCount()
55     listSelected = []
56     for i in range(selNumber):
57         listSelected.append(self.getSelected(i))
58     return listSelected
59
60     #--------------------------------------------------------------------------
61
62 def hasDesktop():
63     return IN_SALOME_GUI
64
65     #--------------------------------------------------------------------------
66
67 salome_iapp_initial = 1
68
69 class SalomeOutsideGUI(object):
70     """
71     Provides a replacement for class SalomeGUI outside GUI process.
72     Do almost nothing
73     """
74     global myStudyName
75     
76     def hasDesktop(self):
77         """Indicate if GUI is running"""
78         return False
79     
80     def updateObjBrowser(self):
81         """update the GUI object browser"""
82         print("SalomeOutsideGUI: no objectBrowser update outside GUI")
83         pass
84     
85     def getStudyName(self):
86         """Get the study name"""
87         print("SalomeOutsideGUI.getStudyName: avoid use outside GUI")
88         return myStudyName
89     
90     def SelectedCount(self):
91         """Get the number of active selections"""
92         print("SalomeOutsideGUI: no selection mechanism available outside GUI")
93         return 0
94     
95     def getSelected(self, i):
96         """Get the selection number i """
97         print("SalomeOutsideGUI: no selection mechanism available outside GUI")
98         return none
99     
100     def AddIObject(self, Entry):
101         """Add an entry"""
102         print("SalomeOutsideGUI.AddIOObject: not available outside GUI")
103         pass
104     
105     def RemoveIObject(self, Entry):
106         """Remove an entry"""
107         print("SalomeOutsideGUI.REmoveIOObject: not available outside GUI")
108         pass
109     
110     def ClearIObjects(self):
111         """Clear entries"""
112         print("SalomeOutsideGUI.ClearIOObject: not available outside GUI")
113         pass
114     
115     def Display(self, Entry):
116         """Display an entry"""
117         print("SalomeOutsideGUI.Display: not available outside GUI")
118         pass
119     
120     def DisplayOnly(self, Entry):
121         """Display only an entry"""
122         print("SalomeOutsideGUI.DisplayOnly: not available outside GUI")
123         pass
124     
125     def Erase(self, Entry):
126         """Erase en entry"""
127         print("SalomeOutsideGUI.Erase: not available outside GUI")
128         pass
129     
130     def DisplayAll(self):
131         """Display all"""
132         print("SalomeOutsideGUI.Erase: not available outside GUI")
133         pass
134     
135     def EraseAll(self):
136         """Erase all"""
137         print("SalomeOutsideGUI.EraseAll: not available outside GUI")
138         pass
139
140     def IsInCurrentView(self, Entry):
141         """Indicate if an entry is in current view"""
142         print("SalomeOutsideGUI.IsIncurentView: not available outside GUI")
143         return False
144         
145     def getComponentName(self, ComponentUserName ):
146         """Get component name from component user name"""
147         print("SalomeOutsideGUI.getComponentName: not available outside GUI")
148         return ""
149    
150     def getComponentUserName( self, ComponentName ):
151         """Get component user name from component name"""
152         print("SalomeOutsideGUI.getComponentUserName: not available outside GUI")
153         return ""
154         
155     #--------------------------------------------------------------------------
156
157     
158 def salome_iapp_init(embedded):
159     global salome_iapp_initial
160     global sg,IN_SALOME_GUI
161
162     if salome_iapp_initial:
163         salome_iapp_initial=0
164         if embedded:
165             import libSALOME_Swig
166         
167             class SalomeGUI(libSALOME_Swig.SALOMEGUI_Swig):
168                 getAllSelected = SalomeGUIgetAllSelected
169
170             # create a SALOMEGUI_Swig instance
171             sg = SalomeGUI()
172             inSalomeGUI = sg.hasDesktop()
173         else:
174             # Not embedded in GUI
175             sg=SalomeOutsideGUI()
176             inSalomeGUI=0
177         if IN_SALOME_GUI is None:
178           IN_SALOME_GUI = inSalomeGUI
179     return sg
180
181 def salome_iapp_close():
182     global salome_iapp_initial
183     salome_iapp_initial=1
184     pass
185
186