-# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
# File : salome_iapp.py
# Author : Paul RASCLE, EDF
# Module : SALOME
# $Header$
-
+## @package salome_iapp
+# Module salome gives access to Salome GUI resources (if GUI has been launched).
+#
import salome_ComponentGUI
#--------------------------------------------------------------------------
-IN_SALOME_GUI=0
+IN_SALOME_GUI=None
-def ImportComponentGUI(ComponentName):
+def ImportComponentGUI(ComponentName, updateOB=True):
if IN_SALOME_GUI:
libName = "lib" + ComponentName + "_Swig"
command = "from " + libName + " import *"
- exec ( command )
+ exec (command, globals())
constructor = ComponentName + "_Swig()"
+ if not updateOB :
+ constructor = ComponentName + "_Swig( False )"
command = "gui = " + constructor
- exec ( command )
- return gui
+ exec (command, globals())
+ return gui # @UndefinedVariable
else:
- print "Warning: ImportComponentGUI(",ComponentName,") outside GUI !"
- print "calls to GUI methods may crash..."
+ print("Warning: ImportComponentGUI(",ComponentName,") outside GUI !")
+ print("calls to GUI methods may crash...")
return salome_ComponentGUI
#--------------------------------------------------------------------------
salome_iapp_initial = 1
-class SalomeOutsideGUI:
+class SalomeOutsideGUI(object):
"""
Provides a replacement for class SalomeGUI outside GUI process.
Do almost nothing
"""
- global myStudyId, myStudyName
+ global myStudyName
def hasDesktop(self):
+ """Indicate if GUI is running"""
return False
- def updateObjBrowser(self, bid):
- print "SalomeOutsideGUI: no objectBrowser update outside GUI"
+ def updateObjBrowser(self):
+ """update the GUI object browser"""
+ print("SalomeOutsideGUI: no objectBrowser update outside GUI")
pass
- def getActiveStudyId(self):
- print "SalomeOutsideGUI.getActiveStudyId: avoid use outside GUI"
- return myStudyId
-
- def getActiveStudyName(self):
- print "SalomeOutsideGUI.getActiveStudyName: avoid use outside GUI"
+ def getStudyName(self):
+ """Get the study name"""
+ print("SalomeOutsideGUI.getStudyName: avoid use outside GUI")
return myStudyName
def SelectedCount(self):
- print "SalomeOutsideGUI: no selection mecanism available outside GUI"
+ """Get the number of active selections"""
+ print("SalomeOutsideGUI: no selection mechanism available outside GUI")
return 0
def getSelected(self, i):
- print "SalomeOutsideGUI: no selection mecanism available outside GUI"
- return none
+ """Get the selection number i """
+ print("SalomeOutsideGUI: no selection mechanism available outside GUI")
+ return None
def AddIObject(self, Entry):
- print "SalomeOutsideGUI.AddIOObject: not available outside GUI"
+ """Add an entry"""
+ print("SalomeOutsideGUI.AddIOObject: not available outside GUI")
pass
def RemoveIObject(self, Entry):
- print "SalomeOutsideGUI.REmoveIOObject: not available outside GUI"
+ """Remove an entry"""
+ print("SalomeOutsideGUI.REmoveIOObject: not available outside GUI")
pass
def ClearIObjects(self):
- print "SalomeOutsideGUI.ClearIOObject: not available outside GUI"
+ """Clear entries"""
+ print("SalomeOutsideGUI.ClearIOObject: not available outside GUI")
pass
def Display(self, Entry):
- print "SalomeOutsideGUI.Display: not available outside GUI"
+ """Display an entry"""
+ print("SalomeOutsideGUI.Display: not available outside GUI")
pass
def DisplayOnly(self, Entry):
- print "SalomeOutsideGUI.DisplayOnly: not available outside GUI"
+ """Display only an entry"""
+ print("SalomeOutsideGUI.DisplayOnly: not available outside GUI")
pass
def Erase(self, Entry):
- print "SalomeOutsideGUI.Erase: not available outside GUI"
+ """Erase en entry"""
+ print("SalomeOutsideGUI.Erase: not available outside GUI")
pass
def DisplayAll(self):
- print "SalomeOutsideGUI.Erase: not available outside GUI"
+ """Display all"""
+ print("SalomeOutsideGUI.Erase: not available outside GUI")
pass
def EraseAll(self):
- print "SalomeOutsideGUI.EraseAll: not available outside GUI"
+ """Erase all"""
+ print("SalomeOutsideGUI.EraseAll: not available outside GUI")
pass
def IsInCurrentView(self, Entry):
- print "SalomeOutsideGUI.IsIncurentView: not available outside GUI"
+ """Indicate if an entry is in current view"""
+ print("SalomeOutsideGUI.IsIncurrentView: not available outside GUI")
return False
def getComponentName(self, ComponentUserName ):
- print "SalomeOutsideGUI.getComponentName: not available outside GUI"
+ """Get component name from component user name"""
+ print("SalomeOutsideGUI.getComponentName: not available outside GUI")
return ""
def getComponentUserName( self, ComponentName ):
- print "SalomeOutsideGUI.getComponentUserName: not available outside GUI"
+ """Get component user name from component name"""
+ print("SalomeOutsideGUI.getComponentUserName: not available outside GUI")
return ""
#--------------------------------------------------------------------------
# create a SALOMEGUI_Swig instance
sg = SalomeGUI()
- IN_SALOME_GUI = sg.hasDesktop()
+ inSalomeGUI = sg.hasDesktop()
else:
# Not embedded in GUI
sg=SalomeOutsideGUI()
- IN_SALOME_GUI=0
+ inSalomeGUI=0
+ if IN_SALOME_GUI is None:
+ IN_SALOME_GUI = inSalomeGUI
return sg
+
+def salome_iapp_close():
+ global salome_iapp_initial
+ salome_iapp_initial=1
+ pass
+
+
+def register_module_in_study(name, syncCall=True):
+ try:
+ import salome
+ salome.salome_init()
+ session_server = salome.naming_service.Resolve("/Kernel/Session")
+ if session_server:
+ message = "register_module_in_study/"+name
+ if syncCall:
+ session_server.emitMessage(message)
+ else:
+ session_server.emitMessageOneWay(message)
+ except:
+ pass