1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2015 EDF R&D
4 # This file is part of SALOME ADAO module
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 __author__="aribes/gboulant"
26 # Get SALOME PyQt interface
28 __sgPyQt = SalomePyQt.SalomePyQt()
30 import adaoModuleHelper
31 from PyQt4 import QtGui,QtCore
34 QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
37 QtGui.QApplication.restoreOverrideCursor()
39 def gui_warning(parent, msg="An error occurs" ):
41 This function displays a message dialog box displaying the specified message.
43 QtGui.QMessageBox.warning( parent, "Alerte", msg)
45 def getActiveStudyId():
47 This function returns the id of the active study. The concept of active study
48 makes sens only in the GUI context.
50 return salome.sg.getActiveStudyId()
52 def refreshObjectBrowser():
54 Refresh the graphical representation of the SALOME study, in case where the
57 if salome.sg is not None:
58 salome.sg.updateObjBrowser(0)
60 def selectItem(salomeStudyItem):
61 if salome.sg is not None:
62 salome.sg.ClearIObjects()
63 salome.sg.AddIObject(salomeStudyItem)
65 def getSelectedItem(salomeStudyId=-100):
67 Get the current selection. If more than one item are selected, the
68 only first is considered. The object is return (not the id).
69 The item can be of any type, no control is done in this function.
72 raise Exception("GuiHelper.getSelectedItem can't be used without the GUI context")
74 if salomeStudyId != -100:
75 studyEditor = salome.kernel.studyedit.getStudyEditor(salomeStudyId)
76 studyEditor = salome.kernel.studyedit.getStudyEditor()
78 listEntries=salome.sg.getAllSelected()
79 if len(listEntries) >= 1:
80 entry = listEntries[0]
81 item = studyEditor.study.FindObjectID( entry )
84 def getAllSelected(salomeStudyId):
86 Returns all selected items in the specified study.
89 raise OmaException("getSelectedItem can't be used without the GUI context", OmaException.TYPES.DEVEL)
91 study = adaoModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
92 selcount = salome.sg.SelectedCount()
94 for i in range( selcount ):
95 __incObjToMap( seltypes, adaoModuleHelper.getObjectID( study, salome.sg.getSelected( i ) ) )
97 return selcount, seltypes
99 def __incObjToMap( m, id ):
101 Increment object counter in the specified map.
102 Not to be used outside this module.
104 if id not in m: m[id] = 0
110 Returns the active Desktop. Usefull to set the relative position of a dialog box
112 return __sgPyQt.getDesktop()
116 This function displays a message dialog box displaying the specified message.
118 gui_warning(getDesktop(),msg)