1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2024 EDF R&D
5 # This file is part of SALOME ADAO module
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 __author__="aribes/gboulant"
27 # Get SALOME PyQt interface
29 __sgPyQt = SalomePyQt.SalomePyQt()
31 from . import adaoModuleHelper
32 from PyQt5 import QtGui, QtCore
33 from PyQt5.QtWidgets import QApplication, QMessageBox
36 QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
39 QApplication.restoreOverrideCursor()
41 def gui_warning(parent, msg="An error occurs" ):
43 This function displays a message dialog box displaying the specified message.
45 QMessageBox.warning( parent, "Alerte", msg)
47 def gui_information(parent, msg="Information" ):
49 This function displays a message dialog box displaying the specified message.
51 QMessageBox.information( parent, "Information", msg, QMessageBox.Close)
53 #~ def getActiveStudyId():
55 #~ This function returns the id of the active study. The concept of active study
56 #~ makes sens only in the GUI context.
58 #~ return salome.sg.getActiveStudyId()
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)
67 salome.sg.updateObjBrowser()
69 def selectItem(salomeStudyItem):
70 if salome.sg is not None:
71 salome.sg.ClearIObjects()
72 salome.sg.AddIObject(salomeStudyItem)
74 def getSelectedItem():# salomeStudyId=-100):
76 Get the current selection. If more than one item are selected, the
77 only first is considered. The object is return (not the id).
78 The item can be of any type, no control is done in this function.
81 raise Exception("GuiHelper.getSelectedItem can't be used without the GUI context")
83 #~ if salomeStudyId != -100:
84 #~ studyEditor = salome.kernel.studyedit.getStudyEditor(salomeStudyId)
85 studyEditor = salome.kernel.studyedit.getStudyEditor()
87 listEntries=salome.sg.getAllSelected()
88 if len(listEntries) >= 1:
89 entry = listEntries[0]
90 item = studyEditor.study.FindObjectID( entry )
93 def getAllSelected():# salomeStudyId):
95 Returns all selected items in the specified study.
98 raise OmaException("getSelectedItem can't be used without the GUI context", OmaException.TYPES.DEVEL)
100 # study = adaoModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
101 selcount = salome.sg.SelectedCount()
103 for i in range( selcount ):
104 __incObjToMap( seltypes, adaoModuleHelper.getObjectID( salome.sg.getSelected( i ) ) ) # study, salome.sg.getSelected( i ) ) )
106 return selcount, seltypes
108 def __incObjToMap( m, id ):
110 Increment object counter in the specified map.
111 Not to be used outside this module.
113 if id not in m: m[id] = 0
119 Returns the active Desktop. Usefull to set the relative position of a dialog box
121 return __sgPyQt.getDesktop()
125 This function displays a message dialog box displaying the specified message.
127 gui_warning(getDesktop(),msg)
129 def information(msg):
131 This function displays a message dialog box displaying the specified message.
133 gui_information(getDesktop(),msg)