1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # File : salome_iapp.py
25 # Author : Paul RASCLE, EDF
28 ## @package salome_iapp
29 # Module salome gives access to Salome GUI resources (if GUI has been launched).
31 import salome_ComponentGUI
33 #--------------------------------------------------------------------------
37 def ImportComponentGUI(ComponentName, updateOB=True):
39 libName = "lib" + ComponentName + "_Swig"
40 command = "from " + libName + " import *"
41 exec (command, globals())
42 constructor = ComponentName + "_Swig()"
44 constructor = ComponentName + "_Swig( False )"
45 command = "gui = " + constructor
46 exec (command, globals())
47 return gui # @UndefinedVariable
49 print("Warning: ImportComponentGUI(",ComponentName,") outside GUI !")
50 print("calls to GUI methods may crash...")
51 return salome_ComponentGUI
53 #--------------------------------------------------------------------------
55 def SalomeGUIgetAllSelected(self):
56 selNumber = self.SelectedCount()
58 for i in range(selNumber):
59 listSelected.append(self.getSelected(i))
62 #--------------------------------------------------------------------------
67 #--------------------------------------------------------------------------
69 salome_iapp_initial = 1
71 class SalomeOutsideGUI:
73 Provides a replacement for class SalomeGUI outside GUI process.
79 """Indicate if GUI is running"""
82 def updateObjBrowser(self):
83 """update the GUI object browser"""
84 print("SalomeOutsideGUI: no objectBrowser update outside GUI")
87 def getStudyName(self):
88 """Get the study name"""
89 print("SalomeOutsideGUI.getStudyName: avoid use outside GUI")
92 def SelectedCount(self):
93 """Get the number of active selections"""
94 print("SalomeOutsideGUI: no selection mechanism available outside GUI")
97 def getSelected(self, i):
98 """Get the selection number i """
99 print("SalomeOutsideGUI: no selection mechanism available outside GUI")
102 def AddIObject(self, Entry):
104 print("SalomeOutsideGUI.AddIOObject: not available outside GUI")
107 def RemoveIObject(self, Entry):
108 """Remove an entry"""
109 print("SalomeOutsideGUI.REmoveIOObject: not available outside GUI")
112 def ClearIObjects(self):
114 print("SalomeOutsideGUI.ClearIOObject: not available outside GUI")
117 def Display(self, Entry):
118 """Display an entry"""
119 print("SalomeOutsideGUI.Display: not available outside GUI")
122 def DisplayOnly(self, Entry):
123 """Display only an entry"""
124 print("SalomeOutsideGUI.DisplayOnly: not available outside GUI")
127 def Erase(self, Entry):
129 print("SalomeOutsideGUI.Erase: not available outside GUI")
132 def DisplayAll(self):
134 print("SalomeOutsideGUI.Erase: not available outside GUI")
139 print("SalomeOutsideGUI.EraseAll: not available outside GUI")
142 def IsInCurrentView(self, Entry):
143 """Indicate if an entry is in current view"""
144 print("SalomeOutsideGUI.IsIncurrentView: not available outside GUI")
147 def getComponentName(self, ComponentUserName ):
148 """Get component name from component user name"""
149 print("SalomeOutsideGUI.getComponentName: not available outside GUI")
152 def getComponentUserName( self, ComponentName ):
153 """Get component user name from component name"""
154 print("SalomeOutsideGUI.getComponentUserName: not available outside GUI")
157 def UpdateView(self):
158 """Update current view"""
159 print("SalomeOutsideGUI.UpdateView: not available outside GUI")
162 #--------------------------------------------------------------------------
165 def salome_iapp_init(embedded):
166 global salome_iapp_initial
167 global sg,IN_SALOME_GUI
169 if salome_iapp_initial:
170 salome_iapp_initial=0
172 import libSALOME_Swig
174 class SalomeGUI(libSALOME_Swig.SALOMEGUI_Swig):
175 getAllSelected = SalomeGUIgetAllSelected
177 # create a SALOMEGUI_Swig instance
179 inSalomeGUI = sg.hasDesktop()
181 # Not embedded in GUI
182 sg=SalomeOutsideGUI()
184 if IN_SALOME_GUI is None:
185 IN_SALOME_GUI = inSalomeGUI
188 def salome_iapp_close():
189 global salome_iapp_initial
190 salome_iapp_initial=1
194 def register_module_in_study(name, syncCall=True):
198 session_server = salome.naming_service.Resolve("/Kernel/Session")
200 message = "register_module_in_study/"+name
202 session_server.emitMessage(message)
204 session_server.emitMessageOneWay(message)