Salome HOME
59fc60989b8901d425890895690d0e1cfaa2cfb6
[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,parent=parentAppli,flags=Qt.Window)
45       self.setModal(True)
46       self.setupUi(self)
47       self.parentAppli=parentAppli
48       self.verifieInstall()
49       self.code=None
50       self.buttonBox.accepted.disconnect(self.accept)
51       self.buttonBox.accepted.connect(self.choisitCode)
52      # self.pB_OK.clicked.connect(self.choisitCode)
53       #self.pB_cancel.clicked.connect(self.sortie)
54
55   def sortie(self):
56       QDialog.reject(self)
57
58   def verifieInstall(self):
59       self.groupCodes=QButtonGroup(self.groupBox)
60       vars=list(os.environ.items())
61       listeCode=('Adao','Carmel3D','CarmelCND','CF','MAP','MT','PSEN','PSEN_N1','Telemac','ZCracks',)
62       for code in listeCode:
63           dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',code))
64           try :
65              l=os.listdir(dirCode)
66              bouton=QRadioButton(self.groupBox)
67              bouton.setText(code)
68              self.groupCodes.addButton(bouton)
69              self.vlBouton.addWidget(bouton)
70           except :
71              clef="PREFS_CATA_"+code
72              try :
73                 repIntegrateur=os.path.abspath(os.environ[clef])
74                 l=os.listdir(repIntegrateur)
75                 bouton=QRadioButton(self.groupBox)
76                 bouton.setText(code)
77                 bouton.show()
78                 self.groupCodes.addButton(bouton)
79              except :
80                 pass
81       listeCodesIntegrateur=[]
82       for k,v in vars:
83           if re.search('^PREFS_CATA_',k) != None and k[11:] not in listeCode:
84              listeCodesIntegrateur.append(k[11:])
85       for code in listeCodesIntegrateur:
86           try :
87               clef="PREFS_CATA_"+code
88               repIntegrateur=os.path.abspath(os.environ[clef])
89               l=os.listdir(repIntegrateur)
90               bouton=QRadioButton(self)
91               bouton.setText(code)
92               bouton.show()
93               self.groupCodes.addButton(bouton)
94           except :
95               pass
96       self.parentAppli.listeCode=self.parentAppli.listeCode+listeCodesIntegrateur
97
98   def choisitCode(self):
99       bouton=self.groupCodes.checkedButton()
100       if bouton==None : return
101       code=str(bouton.text())
102       codeUpper=code.upper()
103       self.parentAppli.code=codeUpper
104       try :
105           dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',code))
106           l=os.listdir(dirCode)
107           sys.path.insert(0,dirCode)
108       except :
109           clef="PREFS_CATA_"+code
110           repIntegrateur=os.path.abspath(os.environ[clef])
111           l=os.listdir(repIntegrateur)
112           sys.path.insert(0,repIntegrateur)
113       self.close()