Salome HOME
e362e581101915575b6537d9ed1c773e6a196c0a
[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 import os,sys,re
24 from desChoixCode import Ui_ChoixCode
25 f monEnvQT5:
26     from PyQt5.QtWidgets import QDialog, QRadioButton
27     from PyQt5.QtGui import QPalette
28     from PyQt5.QtCore import QProcess, QFileInfo, Qt
29 else :
30     from PyQt4.QtGui  import *
31     from PyQt4.QtCore import *
32
33     
34 # Import des panels
35
36 class MonChoixCode(Ui_ChoixCode,QDialog):
37   """
38   Classe définissant le panel associé aux mots-clés qui demandent
39   à l'utilisateur de choisir une seule valeur parmi une liste de valeurs
40   discrètes
41   """
42   def __init__(self,  parentAppli=None):
43       QDialog.__init__(self,parentAppli)
44       self.setModal(True)
45       self.setupUi(self)
46       self.parentAppli=parentAppli
47       self.verifieInstall()
48       self.code=None
49       if monEnvQT5:
50          self.pB_OK.clicked.connect(self.choisitCode)
51          self.pB_cancel.clicked.connect(self.sortie)
52       else :
53          self.connect(self.pB_OK,SIGNAL("clicked()"),self.choisitCode)
54          self.connect(self.pB_cancel,SIGNAL("clicked()"),self.sortie)
55
56   def sortie(self):
57       QDialog.reject(self)
58
59   def verifieInstall(self):
60       self.groupCodes=QButtonGroup(self.groupBox)
61       vars=os.environ.items()
62       listeCode=('Aster','Adao','Carmel3D','CarmelCND','CF','MAP','MT','PSEN','Telemac','ZCracks',)
63       i=1
64       for code in listeCode:
65           nom='rB_'+code
66           dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',code))
67           try :
68              l=os.listdir(dirCode)
69              bouton=QRadioButton(self)
70              bouton.setMinimumSize(QSize(0, 30))
71              bouton.setText(code)
72              bouton.setGeometry(QRect(10,20+30*i, 300, 30))
73              bouton.show()
74              self.groupCodes.addButton(bouton)
75              i=i+1
76           except :
77              clef="PREFS_CATA_"+code
78              try :
79                 repIntegrateur=os.path.abspath(os.environ[clef])
80                 l=os.listdir(repIntegrateur)
81                 bouton=QRadioButton(self)
82                 bouton.setGeometry(QRect(10,20+30*i, 300, 30))
83                 bouton.setMinimumSize(QSize(0, 30))
84                 bouton.setText(code)
85                 bouton.show()
86                 i=i+1
87                 self.groupCodes.addButton(bouton)
88              except :
89                 pass
90       listeCodesIntegrateur=[]
91       for k,v in vars:
92           if re.search('^PREFS_CATA_',k) != None and k[11:] not in listeCode:
93              listeCodesIntegrateur.append(k[11:])
94       for code in listeCodesIntegrateur:
95           try :
96               clef="PREFS_CATA_"+code
97               repIntegrateur=os.path.abspath(os.environ[clef])
98               l=os.listdir(repIntegrateur)
99               bouton=QRadioButton(self)
100               bouton.setGeometry(QRect(10,20+30*i, 300, 30))
101               i=i+1
102               bouton.setMinimumSize(QSize(0, 30))
103               bouton.setText(code)
104               bouton.show()
105               self.groupCodes.addButton(bouton)
106           except :
107               pass
108       self.parentAppli.ListeCode=self.parentAppli.ListeCode+listeCodesIntegrateur
109
110   def choisitCode(self):
111       bouton=self.groupCodes.checkedButton()
112       code=str(bouton.text())
113       codeUpper=code.upper()
114       self.parentAppli.code=codeUpper
115       try :
116           dirCode=os.path.abspath(os.path.join(os.path.abspath(__file__),'../..',code))
117           l=os.listdir(dirCode)
118           sys.path.insert(0,dirCode)
119       except :
120           clef="PREFS_CATA_"+code
121           repIntegrateur=os.path.abspath(os.environ[clef])
122           l=os.listdir(repIntegrateur)
123           sys.path.insert(0,repIntegrateur)
124       self.close()