Salome HOME
legere difference ds VARIABLES_TO_BE...
[tools/eficas.git] / InterfaceQT4 / monChoixCode.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Modules Python
21 # Modules Eficas
22
23 from __future__ import absolute_import
24 try :
25    from builtins import str
26 except : pass
27
28 import os,sys,re
29 from desChoixCode import Ui_ChoixCode
30 from PyQt5.QtWidgets import QDialog, QRadioButton, QGroupBox, QButtonGroup
31 from PyQt5.QtGui import QPalette
32 from PyQt5.QtCore import QProcess, QFileInfo, Qt, QSize
33
34     
35 # Import des panels
36
37 class MonChoixCode(Ui_ChoixCode,QDialog):
38   """
39   Classe definissant le panel associe aux mots-cles qui demandent
40   a l'utilisateur de choisir une seule valeur parmi une liste de valeurs
41   discretes
42   """
43   def __init__(self,  parentAppli=None):
44       QDialog.__init__(self,parentAppli)
45       self.setModal(True)
46       self.setupUi(self)
47       self.parentAppli=parentAppli
48       self.verifieInstall()
49       self.code=None
50       self.pB_OK.clicked.connect(self.choisitCode)
51       self.pB_cancel.clicked.connect(self.sortie)
52
53   def sortie(self):
54       QDialog.reject(self)
55
56   def verifieInstall(self):
57       self.groupCodes=QButtonGroup(self.groupBox)
58       vars=list(os.environ.items())
59       listeCode=('Aster','Adao','Carmel3D','CarmelCND','CF','MAP','MT','PSEN','PSEN_N1','Telemac','ZCracks',)
60       for code in listeCode:
61           dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',code))
62           try :
63              l=os.listdir(dirCode)
64              bouton=QRadioButton(self.groupBox)
65              bouton.setText(code)
66              self.groupCodes.addButton(bouton)
67              self.vlBouton.addWidget(bouton)
68           except :
69              clef="PREFS_CATA_"+code
70              try :
71                 repIntegrateur=os.path.abspath(os.environ[clef])
72                 l=os.listdir(repIntegrateur)
73                 bouton=QRadioButton(self.groupBox)
74                 bouton.setText(code)
75                 bouton.show()
76                 self.groupCodes.addButton(bouton)
77              except :
78                 pass
79       listeCodesIntegrateur=[]
80       for k,v in vars:
81           if re.search('^PREFS_CATA_',k) != None and k[11:] not in listeCode:
82              listeCodesIntegrateur.append(k[11:])
83       for code in listeCodesIntegrateur:
84           try :
85               clef="PREFS_CATA_"+code
86               repIntegrateur=os.path.abspath(os.environ[clef])
87               l=os.listdir(repIntegrateur)
88               bouton=QRadioButton(self)
89               bouton.setText(code)
90               bouton.show()
91               self.groupCodes.addButton(bouton)
92           except :
93               pass
94       self.parentAppli.listeCode=self.parentAppli.listeCode+listeCodesIntegrateur
95
96   def choisitCode(self):
97       bouton=self.groupCodes.checkedButton()
98       if bouton==None : return
99       code=str(bouton.text())
100       codeUpper=code.upper()
101       self.parentAppli.code=codeUpper
102       try :
103           dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',code))
104           l=os.listdir(dirCode)
105           sys.path.insert(0,dirCode)
106       except :
107           clef="PREFS_CATA_"+code
108           repIntegrateur=os.path.abspath(os.environ[clef])
109           l=os.listdir(repIntegrateur)
110           sys.path.insert(0,repIntegrateur)
111       self.close()