]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/configuration.py
Salome HOME
Modifications liees a MT
[tools/eficas.git] / InterfaceQT4 / configuration.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017   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 """
21     Ce module sert pour charger les parametres de configuration d'EFICAS
22 """
23 # Modules Python
24 from __future__ import absolute_import
25 try :
26    from builtins import str
27    from builtins import range
28    from builtins import object
29 except : pass
30
31 import os, sys,  types, re
32 import traceback
33 from PyQt5.QtWidgets import QMessageBox
34 from  Editeur.Eficas_utils import read_file
35 from Extensions.i18n import tr
36
37
38 class configBase(object):
39
40   #-------------------------------
41   def __init__(self,appli,repIni):
42   #-------------------------------
43
44   # Classe de base permettant de lire, afficher
45   # et sauvegarder les fichiers utilisateurs 
46   # On a deux directories : la directory generale (Repertoire d install + Nom du code
47   #                       Par exemple : ~/Install_Eficas/EficasV1_14/Openturns_Wrapper
48   # et la directorie de l utilisateur 
49   #                       HOME/.Eficas_Openturns
50   # Le fichier prefs.py va etre lu dans la directory generale 
51   #         puis surcharge eventuellement par celui contenu dans ${PREFS_CATA_$CODE} 
52   #         par celui de l utilisateur
53   # le fichier de catalogue va etre lu dans la directory de l utilisateur s il exite
54   # dans le fichier general sinon
55
56       self.appli   = appli  
57       self.code    = appli.code
58       self.salome  = appli.salome
59       if self.salome : self.name="editeur_salome.ini"
60       else           : self.name="editeur.ini"
61       self.rep_mat = None
62       self.repIni  = repIni
63      
64       if self.code == None : self.code=''
65       if sys.platform[0:5]=="linux" :
66               self.rep_user   = os.path.join(os.environ['HOME'],'.config/Eficas',self.code)
67       else :
68               self.rep_user   = os.path.join('C:/','.config/Eficas',self.code)
69
70
71       self.setValeursParDefaut()
72       
73       if self.code != '' :
74          self.lectureFichierIniStandard()
75          self.lectureFichierIniIntegrateur()
76          self.lectureFichierIniUtilisateur()
77
78       if self.boutonDsMenuBar:
79          self.closeAutreCommande = True
80          self.closeFrameRechercheCommande = True
81
82       #Particularite des schemas MAP
83       if hasattr(self,'make_ssCode'): self.make_ssCode(self.ssCode)
84
85       #if self.appli: self.parent=appli.top
86       #else:         self.parent=None
87
88       if not os.path.isdir(self.savedir) :
89         if sys.platform[0:5]=="linux" :
90           self.savedir=os.environ['HOME']
91         else:
92           self.savedir='C:/'
93       
94
95
96   def setValeursParDefaut(self):
97   #-----------------------------
98   
99       # Valeurs par defaut
100       if not os.path.isdir(self.rep_user) : os.makedirs(self.rep_user)
101       self.path_doc     = os.path.abspath(os.path.join(self.repIni,'..','Doc'))
102       self.exec_acrobat = 'acroread'
103       nomDir="Eficas_"+self.code
104       if sys.platform[0:5]=="linux" :
105         self.savedir   = os.path.abspath(os.path.join(os.environ['HOME'],nomDir))
106       else:
107         self.savedir = os.path.abspath('C:/')
108       self.modeNouvCommande='initial'
109       self.affiche="alpha"
110       self.closeAutreCommande = False
111       self.closeFrameRechercheCommande = False
112       self.closeEntete = False
113       self.closeArbre = False
114       self.force_langue=False
115       self.suiteTelemac=False
116       self.nombreDeBoutonParLigne=0
117       self.translatorFichier=None
118       self.dicoImages= {}
119       self.dicoIcones= {}
120       self.afficheCommandesPliees = True
121       self.simpleClic= False
122       self.afficheOptionnelVide=False
123       self.afficheListesPliees=True
124       self.boutonDsMenuBar=False
125       self.ficIcones=None
126       self.repIcones=None
127       self.differencieSiDefaut=False
128       self.typeDeCata='Python'
129       self.dumpXSD=False
130       self.withXSD=False
131       self.afficheIhm=True
132       self.closeParenthese=False
133       self.enleverActionStructures=False
134       self.enleverParametres=False
135       self.enleverSupprimer=False
136       self.ajoutExecution=False
137       self.utilParExtensions=False
138       self.rendVisiblesLesCaches=False
139
140
141
142  
143   #--------------------------------------
144   def lectureFichierIniStandard(self):
145   #--------------------------------------
146
147       name='prefs_'+self.appli.code
148       prefsCode=__import__(name)
149       for k in dir(prefsCode):
150           if (k[0:1] != "__" and k[-1:-2] !='__'):
151              valeur=getattr(prefsCode,k)
152              setattr(self,k,valeur)
153        
154
155
156   #--------------------------------------
157   def lectureFichierIniIntegrateur(self):
158   #--------------------------------------
159   # Verifie l'existence du fichier "standard"
160   # appelle la lecture de ce fichier
161       clef="PREFS_CATA_"+self.code
162       try :
163         repIntegrateur=os.path.abspath(os.environ[clef])
164       except :
165         return
166       
167       fic_ini_integrateur=os.path.join(repIntegrateur,self.name)
168       if not os.path.isfile(fic_ini_integrateur): return
169       txt = read_file(fic_ini_integrateur)
170       d=locals()
171       try:
172          exec(txt, d)
173       except :
174          QMessageBox.critical( None, tr("Import du fichier de Configuration"), 
175                         tr("Erreur a la lecture du fichier de configuration %s " , str(fic_ini_integrateur)))
176          return
177       self.labels_eficas.append('rep_aide')
178       for k in self.labels_eficas :
179          try :
180             setattr(self,k,d[k])
181          except :
182             pass
183       #Glut pour les repertoires materiaux
184       #et pour la doc
185       for k in d :
186           if (k[0:8]=="rep_mat_") or (k[0:8]=="rep_doc_"):
187              setattr(self,k,d[k])
188
189
190   #--------------------------------------
191   def lectureFichierIniUtilisateur(self):
192   #--------------------------------------
193   # Surcharge les parametres standards par les parametres utilisateur s'ils existent
194       self.fic_ini_utilisateur = os.path.join(self.rep_user,self.name)
195       if not os.path.isfile(self.fic_ini_utilisateur): return
196
197       txt = read_file(self.fic_ini_utilisateur)
198       d=locals()
199       try:
200          exec(txt, d)
201       except :
202          l=traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2])
203          QMessageBox.critical( None, tr("Import du fichier de Configuration"), 
204                         tr("Erreur a la lecture du fichier de configuration %s " , str(fic_ini_integrateur)))
205       for k in self.labels_user :
206          try :
207             setattr(self,k,d[k])
208          except :
209             pass
210       for k in d :
211           if (k[0:8]=="rep_mat_") or (k[0:8]=="rep_doc_"):
212              setattr(self,k,d[k])
213
214   #--------------------------------------
215   def saveParams(self):
216   #--------------------------------------
217   # sauvegarde
218   # les nouveaux parametres dans le fichier de configuration utilisateur
219   #
220       texte=""
221       for clef in self.labels_user :
222           if hasattr(self,clef):
223              valeur=getattr(self,clef)
224              texte= texte + clef+"      = " + repr(valeur) +"\n"
225       #Glut pour les repertoires materiaux
226       #et pour la doc
227       for k in dir(self):
228           if (k[0:8]=="rep_mat_") or (k[0:8]=="rep_doc_"):
229              valeur=getattr(self,k)
230              texte= texte + k+" = " + repr(valeur) +"\n"
231
232       f=open(self.fic_ini_utilisateur,'w+')
233       f.write(texte) 
234       f.close()
235 #
236
237