1 # Copyright (C) 2012-2013 EDF
3 # This file is part of SALOME HYDRO module.
5 # SALOME HYDRO module is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # SALOME HYDRO module is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with SALOME HYDRO module. If not, see <http://www.gnu.org/licenses/>.
19 #from PyQt4 import QtCore, QtGui
20 from PyQt5.QtWidgets import QApplication
21 from PyQt5.QtGui import QCursor
22 from PyQt5.QtCore import Qt
25 from salome.kernel.studyedit import getStudyEditor
28 class HSGUIException(Exception):
30 Exception class used to display user-friendly messages in a dialog box for
31 standard errors (missing files, etc.).
36 class OverrideCursorCM:
38 This class is a context manager that can be used to set an override cursor
39 in a QT application and automatically restore the base cursor
41 def __init__(self, cursor):
45 #QtGui.QApplication.setOverrideCursor(self.cursor)
46 QApplication.setOverrideCursor(self.cursor)
48 def __exit__(self, exc_type, exc_value, traceback):
49 #QtGui.QApplication.restoreOverrideCursor()
50 QApplication.restoreOverrideCursor()
52 #wait_cursor = OverrideCursorCM(QCursor(QtCore.Qt.WaitCursor))
53 wait_cursor = OverrideCursorCM(QCursor(Qt.WaitCursor))
56 def get_and_check_selected_file_path():
58 Get the first selected item in the object browser, check that its "Comment"
59 attribute contains a valid file path, and return this file path.
62 if len(salome.sg.getAllSelected()) == 0 : return None
63 sobj = ed.study.FindObjectID(salome.sg.getSelected(0))
64 filepath = sobj.GetComment()
65 if not os.path.isfile(filepath):
66 #raise HSGUIException(QtGui.QApplication.translate("get_and_check_selected_file_path",
67 raise HSGUIException(QApplication.translate("get_and_check_selected_file_path",
68 "File %1 does not exist").arg(filepath))