1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Ce module sert pour charger les parametres de configuration d'EFICAS
24 from __future__ import absolute_import
26 from builtins import str
27 from builtins import range
28 from builtins import object
31 import os, sys, types, re
33 from PyQt5.QtWidgets import QMessageBox
34 from Editeur.Eficas_utils import read_file
35 from Extensions.i18n import tr
38 class configBase(object):
40 #-------------------------------
41 def __init__(self,appli,repIni):
42 #-------------------------------
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
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"
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)
68 self.rep_user = os.path.join('C:/','.config/Eficas',self.code)
71 self.setValeursParDefaut()
74 self.lectureFichierIniStandard()
75 self.lectureFichierIniIntegrateur()
76 self.lectureFichierIniUtilisateur()
78 if self.boutonDsMenuBar:
79 self.closeAutreCommande = True
80 self.closeFrameRechercheCommande = True
82 #Particularite des schemas MAP
83 if hasattr(self,'make_ssCode'): self.make_ssCode(self.ssCode)
85 #if self.appli: self.parent=appli.top
86 #else: self.parent=None
88 if not os.path.isdir(self.savedir) :
89 if sys.platform[0:5]=="linux" :
90 self.savedir=os.environ['HOME']
96 def setValeursParDefaut(self):
97 #-----------------------------
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))
107 self.savedir = os.path.abspath('C:/')
108 self.modeNouvCommande='initial'
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
120 self.afficheCommandesPliees = True
121 self.simpleClic= False
122 self.afficheOptionnelVide=False
123 self.afficheListesPliees=True
124 self.boutonDsMenuBar=False
127 self.differencieSiDefaut=False
128 self.typeDeCata='Python'
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
143 #--------------------------------------
144 def lectureFichierIniStandard(self):
145 #--------------------------------------
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)
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
163 repIntegrateur=os.path.abspath(os.environ[clef])
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)
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)))
177 self.labels_eficas.append('rep_aide')
178 for k in self.labels_eficas :
183 #Glut pour les repertoires materiaux
186 if (k[0:8]=="rep_mat_") or (k[0:8]=="rep_doc_"):
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
197 txt = read_file(self.fic_ini_utilisateur)
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 :
211 if (k[0:8]=="rep_mat_") or (k[0:8]=="rep_doc_"):
214 #--------------------------------------
215 def saveParams(self):
216 #--------------------------------------
218 # les nouveaux parametres dans le fichier de configuration utilisateur
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
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"
232 f=open(self.fic_ini_utilisateur,'w+')