Salome HOME
pb d accent. on les enleve en français
[tools/eficas.git] / InterfaceQT4 / monWidgetCreeParam.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 import string,types,os,re
22 pattern_name       = re.compile(r'^[^\d\W]\w*\Z')
23
24 # Modules Eficas
25
26 from PyQt4 import *
27 from PyQt4.QtGui import *
28 from PyQt4.QtCore import *
29 from Extensions.i18n import tr
30 from desWidgetCreeParam import Ui_desWidgetCreeParam
31
32
33 class MonWidgetCreeParam(Ui_desWidgetCreeParam,QDialog):
34   """
35   """
36   def __init__(self,editor, name = None,fl = 0):
37        self.editor=editor
38        QDialog.__init__(self,editor)
39        self.setupUi(self)
40        self.connecterSignaux()
41        self.dejaExistant=0
42        self.listeTousParam=self.editor.jdc.params
43        self.dictListe={}
44        self.initToutesVal()
45
46   def connecterSignaux(self) :
47         self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.lineEditValReturnPressed)
48         self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.lineEditNomReturnPressed)
49
50
51   def CreeParametre(self):
52         nom=str(self.lineEditNom.text())
53         val=str(self.lineEditVal.text())
54         if val == "" or None : return
55         if nom == "" or None : return
56         if len(self.editor.tree.selectedItems()) == 0 : 
57            itemAvant=self.editor.tree.racine 
58         else :                                     
59            itemAvant=self.editor.tree.selectedItems()[0]
60         param=itemAvant.addParameters(True)
61         param.item.set_nom(nom)
62         param.item.set_valeur(val)
63         param.update_node_texte()
64         self.LBParam.addItem(QString(repr(param.item)))
65
66
67   def lineEditValReturnPressed(self):
68         qtVal=self.lineEditVal.text()
69         valString=str(self.lineEditVal.text())
70         contexte={}
71         exec "from math import *" in contexte
72         jdc=self.editor.jdc
73         if jdc == None : 
74           self.editor.affiche_infos(tr(u"La Creation de parametre n est possible que dans un jeu de donnees"),Qt.red)
75           return
76
77         for p in jdc.params :
78            try:
79               tp=p.nom+'='+str(repr(p.valeur))
80               exec tp  in contexte
81            except :
82               pass
83         monTexte="monParam="+valString
84         try :
85           exec monTexte in contexte
86         except :
87           self.editor.affiche_infos(tr("Valeur incorrecte"),Qt.red)
88         if self.lineEditNom.text()!="" and self.dejaExistant==False : self.CreeParametre()
89
90
91   def lineEditNomReturnPressed(self):
92         qtNom=self.lineEditNom.text()
93         nom=str(qtNom)
94         if not pattern_name.match(nom) :
95            self.lineEditNom.setText("")
96            commentaire=nom + tr(" n est pas un identifiant correct\n ")
97            self.editor.affiche_infos(commentaire,Qt.red)
98         for p in self.editor.jdc.params :
99            if p.nom==nom :
100              commentaire=nom + tr(" existe deja\n ")
101              self.editor.affiche_infos(commentaire,Qt.red)
102              return
103
104         if self.lineEditVal.text()!="" : self.CreeParametre()
105         self.lineEditVal.setFocus(Qt.OtherFocusReason)
106
107
108   def initToutesVal(self):
109         self.LBParam.clear()
110         for param in self.listeTousParam :
111             self.LBParam.addItem(QString(repr(param)))
112             self.dictListe[QString(repr(param))] = param
113
114   def valideParam(self):
115         if self.LBParam.selectedItems()== None : return
116         lParam=[]
117         for indice in range(len(self.LBParam.selectedItems())):
118             i=self.LBParam.selectedItems()[indice].text()
119             param=self.dictListe[i]
120             lParam.append(param)
121
122         try :
123           self.panel.AjoutNValeur(lParam)
124         except :
125           for p in lParam :
126              self.panel.Ajout1Valeur(p)
127         self.close()
128