Salome HOME
Nettoyage des menus
[modules/hydrosolver.git] / src / salome_hydro / run_study / eficas / appli.py
1 #  Copyright (C) 2012-2013 EDF
2 #
3 #  This file is part of SALOME HYDRO module.
4 #
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.
9 #
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.
14 #
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/>.
17
18 import os
19 import sys
20
21 from PyQt5.QtWidgets import QMessageBox, QScrollArea, QGridLayout
22
23
24 import salome
25 import SalomePyQt
26 sgPyQt = SalomePyQt.SalomePyQt()
27
28 from salome.kernel.logger import Logger
29 from salome.kernel import termcolor
30 logger = Logger("salome.hydro.run_study.eficas.appli",
31                 color=termcolor.GREEN_FG)
32
33 import eficasSalome
34
35 from salome.hydro.study import HydroStudyEditor
36
37 class EficasForRunStudyAppli(eficasSalome.MyEficas):
38     """
39     This class launches Eficas and adds entries for the created files in
40     HYDRO component in the study tree.
41
42     :type  fichier: string
43     :param fichier: path of an Eficas file to open
44
45     """
46     def __init__(self, fichier=None, version=None):
47         self.ed = HydroStudyEditor()
48         self.codedir = os.path.dirname(__file__)
49         sys.path[:0] = [self.codedir]
50         area = QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
51         eficasSalome.MyEficas.__init__(self, area, code="run_study",
52                                        fichier=fichier, version=version)
53         gridLayout = QGridLayout(area)
54         gridLayout.addWidget(self)
55         area.setWidgetResizable(1)
56         sgPyQt.createView("Eficas Run_Study", self)
57         if fichier == None:
58             self.fileNew()
59         else:
60             self.addJdcInSalome(fichier)
61
62     def addJdcInSalome(self, jdcPath):
63         """
64         Add the newly created file in Salome study
65         """
66         try:
67             self.ed.find_or_create_run_study(jdcPath)
68         except Exception, exc:
69             msgError = "Can't add file to Salome study tree"
70             logger.exception(msgError)
71             QMessageBox.warning(self, self.tr("Warning"),
72                                 self.tr("%s. Reason:\n%s\n\nSee logs for more details." % (msgError, exc)))
73         salome.sg.updateObjBrowser(0)
74
75     def closeEvent(self, event):
76         while self.codedir in sys.path:
77             sys.path.remove(self.codedir)
78         eficasSalome.MyEficas.closeEvent(self, event)