Salome HOME
ee665f1c1292eb48ab6d1d9413498dae51f94369
[modules/hydrosolver.git] / src / salome_hydro / pytel / genjobwindow.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 from PyQt5.QtWidgets import QDialog , QFileDialog
20
21 import salome
22 from salome.hydro.pytel.genjob import generate_job
23 from genjobwindow_ui import Ui_GenJobDialog
24
25
26 class GenJobDialog(QDialog, Ui_GenJobDialog):
27
28   def __init__(self, parent, pytel_params):
29     QDialog.__init__(self, parent)
30     self.setupUi(self)
31     self.dialogButtonBox.accepted.connect(self.validate)
32     self.dialogButtonBox.rejected.connect( self.close)
33     self.chooseInputDataDirectoryButton.clicked.connect( self.choose_input_dir)
34     self.chooseResultDirectoryButton.clicked.connect(self.choose_result_dir)
35
36     self.telemacRootDirLE.setText("/projets/systel/V7P2")
37     self.telemacEnvFileLE.setText("/projets/systel/V7P2/config/pysource.eole.intel.sh")
38     casedir = os.path.dirname(pytel_params["FICHIER_CAS"])
39     self.inputDataDirectoryLE.setText(casedir)
40     self.resultDirectoryLE.setText(casedir)
41
42     # Populate resource combo box
43     res_manager = salome.naming_service.Resolve("/ResourcesManager")
44     res_params = salome.ResourceParameters()
45     res_list = res_manager.GetFittingResources(res_params)
46     self.resourceCB.addItems(res_list)
47
48     self.pytel_params = pytel_params
49
50   def choose_input_dir(self):
51     directory = QFileDialog.getExistingDirectory(self,
52             directory = self.inputDataDirectoryLE.text(),
53             options = QFileDialog.ShowDirsOnly)
54     if not directory.isNull():
55       self.inputDataDirectoryLE.setText(directory)
56
57   def choose_result_dir(self):
58     directory = QFileDialog.getExistingDirectory(self,
59             directory = self.resultDirectoryLE.text(),
60             options = QFileDialog.ShowDirsOnly)
61     if not directory.isNull():
62       self.resultDirectoryLE.setText(directory)
63
64   def validate(self):
65     generate_job(self.pytel_params,
66                  str(self.resourceCB.currentText()),
67                  str(self.telemacRootDirLE.text()),
68                  str(self.telemacEnvFileLE.text()),
69                  self.nbCoreSB.value(),
70                  str(self.inputDataDirectoryLE.text()),
71                  str(self.resultDirectoryLE.text()))
72     self.close()