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