1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Guillaume Boulant (EDF/R&D)
23 # ==================================================================
24 # This file provides helper functions to drive some gui features of a
25 # SALOME Application (the selection in the object browser for now,
26 # further development coming soon). Note that some of these helper
27 # functions are specialized for a GEOM or SMESH context (see the
28 # guihelper.py modules comming with the packages salome.geom and
30 # ==================================================================
33 # ==================================================================
34 # Definition of usefull objects and functions to deal with the SALOME
36 # ==================================================================
39 from salome.kernel import services
42 # Get SALOME PyQt interface to manipulate the GUI context
43 # (Get the active study for example. Note that the active study is a
44 # GUI concept only: it is the study that is currently active in the
48 sgPyQt=SalomePyQt.SalomePyQt()
51 # Get SALOME Swig interface to manipulate the GUI widget
54 SalomeGUI = libSALOME_Swig.SALOMEGUI_Swig()
57 # ==================================================================
58 # Functions to manipulate the objects in the browser (generic)
59 # ==================================================================
61 def getSObjectSelected():
63 Returns the sobject and the entry of the item currently selected
64 in the objects browser. Returns "None, None" if no item is
65 selected. If several objects are selected, it returns the first
70 study = salome.myStudy
71 if SalomeGUI.SelectedCount() == 1:
72 # We only considere the first element of the list. If you need
73 # something else, create another function in your own context.
74 entry = SalomeGUI.getSelected( 0 )
76 sobj = study.FindObjectID( entry )
79 def showSObjectSelected():
81 This function print the attributes of the selected object.
82 (this function is only for test purpose)
84 sobj, entry = getSObjectSelected()
86 test, attr = sobj.FindAttribute( "AttributeName" )
88 message = "My name is '%s'" % attr.Value()
92 def deleteSObjectSelected():
94 This function deletes the selected object.
96 sobj, entry = getSObjectSelected()
98 study = salome.myStudy
99 builder = study.NewBuilder()
100 builder.RemoveObject( sobj )
101 SalomeGUI.updateObjBrowser()
105 # ==================================================================
106 # Use cases and demo functions
107 # ==================================================================
110 # CAUTION: Before running this test functions, you first have to
111 # create (or import) an object and select this object in the objects
116 # - the SObject is an item in the study (Study Object).
117 # - the entry is the identifier of an item.
118 # - the object (geom object or smesh object) is a CORBA servant
119 # embedded in the SALOME component container and with a reference in
120 # the SALOME study, so that it can be retrieved.
123 def TEST_getSObjectSelected():
124 mySObject, myEntry = getSObjectSelected()
125 myName = mySObject.GetName()
126 print("The name of the selected object is %s"%myName)
128 def TEST_showSObjectSelected():
129 showSObjectSelected()
131 if __name__ == "__main__":
132 TEST_getSObjectSelected()
133 TEST_showSObjectSelected()