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