Salome HOME
Report validation of ADAO Case using Eficas and documentation improvement
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoGuiHelper.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2016 EDF R&D
3 #
4 # This file is part of SALOME ADAO module
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 __author__="aribes/gboulant"
24
25 import salome
26 # Get SALOME PyQt interface
27 import SalomePyQt
28 __sgPyQt = SalomePyQt.SalomePyQt()
29
30 import adaoModuleHelper
31 from daUtils.qtversion import useQT5
32 if useQT5:
33     from PyQt5 import QtGui, QtCore
34     from PyQt5.QtWidgets import QApplication, QMessageBox
35 else:
36     from PyQt4 import QtGui, QtCore
37     from PyQt4.QtGui import QApplication, QMessageBox
38
39 def waitCursor():
40     QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
41
42 def restoreCursor():
43     QApplication.restoreOverrideCursor()
44
45 def gui_warning(parent, msg="An error occurs" ):
46     """
47     This function displays a message dialog box displaying the specified message.
48     """
49     QMessageBox.warning( parent, "Alerte", msg)
50
51 def gui_information(parent, msg="Information" ):
52     """
53     This function displays a message dialog box displaying the specified message.
54     """
55     QMessageBox.information( parent, "Information", msg, QMessageBox.Close)
56
57 def getActiveStudyId():
58     """
59     This function returns the id of the active study. The concept of active study
60     makes sens only in the GUI context.
61     """
62     return salome.sg.getActiveStudyId()
63
64 def refreshObjectBrowser():
65     """
66     Refresh the graphical representation of the SALOME study, in case where the
67     GUI is working.
68     """
69     if salome.sg is not None:
70         salome.sg.updateObjBrowser(0)
71
72 def selectItem(salomeStudyItem):
73   if salome.sg is not None:
74     salome.sg.ClearIObjects()
75     salome.sg.AddIObject(salomeStudyItem)
76
77 def getSelectedItem(salomeStudyId=-100):
78     """
79     Get the current selection. If more than one item are selected, the
80     only first is considered. The object is return (not the id).
81     The item can be of any type, no control is done in this function.
82     """
83     if salome.sg is None:
84         raise Exception("GuiHelper.getSelectedItem can't be used without the GUI context")
85
86     if salomeStudyId != -100:
87       studyEditor = salome.kernel.studyedit.getStudyEditor(salomeStudyId)
88     studyEditor = salome.kernel.studyedit.getStudyEditor()
89     item = None
90     listEntries=salome.sg.getAllSelected()
91     if len(listEntries) >= 1:
92         entry = listEntries[0]
93         item = studyEditor.study.FindObjectID( entry )
94     return item
95
96 def getAllSelected(salomeStudyId):
97     """
98     Returns all selected items in the specified study.
99     """
100     if salome.sg is None:
101         raise OmaException("getSelectedItem can't be used without the GUI context", OmaException.TYPES.DEVEL)
102
103     study = adaoModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
104     selcount = salome.sg.SelectedCount()
105     seltypes = {}
106     for i in range( selcount ):
107         __incObjToMap( seltypes, adaoModuleHelper.getObjectID( study, salome.sg.getSelected( i ) ) )
108         pass
109     return selcount, seltypes
110
111 def __incObjToMap( m, id ):
112     """
113     Increment object counter in the specified map.
114     Not to be used outside this module.
115     """
116     if id not in m: m[id] = 0
117     m[id] += 1
118     pass
119
120 def getDesktop():
121     """
122     Returns the active Desktop. Usefull to set the relative position of a dialog box
123     """
124     return __sgPyQt.getDesktop()
125
126 def warning(msg):
127     """
128     This function displays a message dialog box displaying the specified message.
129     """
130     gui_warning(getDesktop(),msg)
131
132 def information(msg):
133     """
134     This function displays a message dialog box displaying the specified message.
135     """
136     gui_information(getDesktop(),msg)