Salome HOME
Redesign SALOME documentation
[modules/gui.git] / doc / salome / gui / input / text_user_interface.rst
1 .. _tui_page: 
2
3 #################################
4 Using SALOME GUI python interface
5 #################################
6
7
8 The extended salome.py Python module provides **sg** variable, which gives access to some GUI functions.
9
10 **Note**, that this variable is not available if you use salome.py
11 Python module outside of the GUI desktop, i.e. without the embedded Python
12 console (since SWIG library is linked directly to the GUI library).
13
14 The example of usage:
15
16 .. code-block:: python
17    :linenos:
18
19         # update Object browser contents
20         salome.sg.updateObjBrowser(True)
21
22         # get the active study ID
23         studyId = salome.sg.getActiveStudyId() 
24
25         # get the active study name
26         studyName = salome.sg.getActiveStudyName()
27
28         # get the selected objects
29         selCount = salome.sg.SelectedCount() # the number of selected items
30         for i in range(selCount):
31             print salome.sg.getSelected(i) # print the entry ID of i-th selected item
32
33 .. code-block:: python
34    :linenos:
35
36         # get the list of IDs of all selected objects
37         selected = salome.sg.getAllSelected()
38
39         # add an object to the selection
40         salome.sg.AddIObject("0:1:1:1") # "0:1:1:1" is an object ID 
41
42         # remove an object from the selection (make it unselected)
43         salome.sg.RemoveIObject("0:1:1:1") # "0:1:1:1" is an object ID 
44
45         # clear the selection (set all objects unselected)
46         salome.sg.ClearIObjects()
47
48         # display an object in the current view (if possible)
49         salome.sg.Display("0:1:1:1") # "0:1:1:1" is an object ID 
50         salome.sg.UpdateView() # update view
51
52         # erase an object from the current view
53         salome.sg.Erase("0:1:1:1") # "0:1:1:1" is an object ID 
54         salome.sg.UpdateView() # update view
55
56         # display all objects in the current view (if possible)
57         salome.sg.DisplayAll()
58         salome.sg.UpdateView() # update view
59
60         # erase all objects from the current view
61         salome.sg.EraseAll()
62         salome.sg.UpdateView() # update view
63
64         # set top, bottom, front, rear, left, right view
65         salome.sg.ViewTop() # top view
66         salome.sg.ViewBottom() # bottom view
67         salome.sg.ViewFront() # front view
68         salome.sg.ViewTop() #  back view
69         salome.sg.ViewLeft() # left view
70         salome.sg.ViewRight() # right view
71
72         # reset the current view
73         salome.sg.ResetView()
74
75         # get the component symbolic name by its user name
76         compName = salome.sg.getComponentName("Geometry") # compoName = "GEOM"
77
78         # get the component user name by its symbolic name
79         compName = salome.sg.getComponentUserName("SMESH") # compoName = "Mesh"
80
81         # ...
82
83