Salome HOME
1er mise en coherence avec la 7_6
[tools/eficas.git] / InterfaceQT4 / monWidgetParam.py
1 # Copyright (C) 2007-2013   EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Modules Python
20 # Modules Eficas
21
22 from desWidgetParam import Ui_WidgetParam
23 from gereIcones import FacultatifOuOptionnel
24 from PyQt4.QtGui import *
25 from PyQt4.QtCore import *
26 from Extensions.i18n import tr
27 from Extensions.eficas_exception import EficasException
28 import Accas 
29 import os, re
30 import string
31 import types
32
33 pattern_name       = re.compile(r'^[^\d\W]\w*\Z')
34
35     
36 # Import des panels
37
38 class MonWidgetParam(QWidget,Ui_WidgetParam,FacultatifOuOptionnel):
39   """
40   """
41   def __init__(self,node,editor,commentaire):
42       QWidget.__init__(self,None)
43       self.node=node
44       self.node.fenetre=self
45       self.setupUi(self)
46       self.editor=editor
47       self.setIconePoubelle()
48       self.remplit()
49       if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
50       else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
51       self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.LEValeurPressed)
52       self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.LENomPressed)
53       self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
54       self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
55       self.connect(self.bVerifie,SIGNAL("clicked()"), self.verifiePressed)
56       self.editor.affiche_infos("")
57
58
59        
60   def afficheCatalogue(self):
61       self.node.tree.racine.affichePanneau()
62       if self.node : self.node.select()
63       else : self.node.tree.racine.select()
64
65   def remplit(self):
66       nom=self.node.item.get_nom()
67       self.lineEditNom.setText(nom)
68
69       valeur=self.node.item.get_valeur()
70       if valeur == None : 
71          self.lineEditVal.clear()
72       elif type(valeur) == types.ListType :
73          texte="["
74          for l in valeur :
75            texte=texte+str(l) +","
76          texte=texte[0:-1]+"]"
77          self.lineEditVal.setText(texte)
78       else :
79          self.lineEditVal.setText(str(valeur))
80
81
82   def donnePremier(self):
83       self.lineEditVal.setFocus(7)
84
85   def LEValeurPressed(self):
86       if self.verifiePressed() == False :
87          QMessageBox.warning( self,tr( "Modification Impossible"),tr( "le parametre n'est pas valide"))
88       nom=str(self.lineEditNom.text())
89       val=str(self.lineEditVal.text())
90       self.node.item.set_nom(nom)
91       self.node.item.set_valeur(val)
92       self.node.update_texte()
93       self.node.update_node_valid()
94
95   def LENomPressed(self):
96       self.LEValeurPressed()
97
98   def verifiePressed(self):
99         nomString=str(self.lineEditNom.text())
100         if not pattern_name.match(nomString) : 
101            self.LECommentaire.setText(nomString + tr(" n est pas un identifiant correct"))
102            return False
103
104         valString=str(self.lineEditVal.text())
105
106         contexte={}
107         exec "from math import *" in contexte
108         jdc=self.node.item.get_jdc()
109         for p in jdc.params :
110            try:
111               tp=p.nom+'='+str(repr(p.valeur))
112               exec tp  in contexte
113            except exc :
114               pass
115
116         monTexte=nomString+"="+valString
117         try :
118           exec monTexte in contexte
119         except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError),  exc:
120           self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
121           return False
122         except :
123           self.LECommentaire.setText(tr("Valeur incorrecte "))
124           return False
125
126         self.LECommentaire.setText(tr("Valeur correcte "))
127         return True
128
129   def afficheApres(self):
130        self.node.selectApres()
131
132   def afficheAvant(self):
133        self.node.selectAvant()
134
135