1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2010 EDF R&D
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.
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__="aribes/gboulant"
24 # Get SALOME PyQt interface
26 __sgPyQt = SalomePyQt.SalomePyQt()
28 import datassimModuleHelper
29 from PyQt4 import QtGui,QtCore
32 QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
35 QtGui.QApplication.restoreOverrideCursor()
37 def gui_warning(parent, msg="An error occurs" ):
39 This function displays a message dialog box displaying the specified message.
41 QtGui.QMessageBox.warning( parent, "Alerte", msg)
43 def getActiveStudyId():
45 This function returns the id of the active study. The concept of active study
46 makes sens only in the GUI context.
48 return __sgPyQt.getStudyId()
53 This function returns the active study reference. The concept of active study
54 makes sens only in the GUI context.
56 studyId = getActiveStudyId()()
57 study = datassimModuleHelper.getStudyManager().GetStudyByID( studyId )
60 def refreshObjectBrowser():
62 Refresh the graphical representation of the SALOME study, in case where the
65 if salome.sg is not None:
66 salome.sg.updateObjBrowser(0)
68 def getSelectedItem(salomeStudyId=getActiveStudyId()):
70 Get the current selection. If more than one item are selected, the
71 only first is considered. The object is return (not the id).
72 The item can be of any type, no control is done in this function.
75 raise Exception("GuiHelper.getSelectedItem can't be used without the GUI context")
77 salomeStudy = datassimModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
80 listEntries=salome.sg.getAllSelected()
81 if len(listEntries) >= 1:
82 entry = listEntries[0]
83 item = salomeStudy.FindObjectID( entry )
87 def getAllSelected(salomeStudyId):
89 Returns all selected items in the specified study.
92 raise OmaException("getSelectedItem can't be used without the GUI context", OmaException.TYPES.DEVEL)
94 study = datassimModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
95 selcount = salome.sg.SelectedCount()
97 for i in range( selcount ):
98 __incObjToMap( seltypes, datassimModuleHelper.getObjectID( study, salome.sg.getSelected( i ) ) )
100 return selcount, seltypes
102 def __incObjToMap( m, id ):
104 Increment object counter in the specified map.
105 Not to be used outside this module.
107 if id not in m: m[id] = 0
113 Returns the active Desktop. Usefull to set the relative position of a dialog box
115 return __sgPyQt.getDesktop()
119 This function displays a message dialog box displaying the specified message.
121 gui_warning(getDesktop(),msg)