Salome HOME
af61dd5c6204aefa678ec4c3f1e1b3ff382525fa
[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.appliEficas=self.editor.appliEficas
48       self.repIcon=self.appliEficas.repIcon
49
50       self.setIconePoubelle()
51       self.remplit()
52       if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
53       else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
54       self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.LEValeurPressed)
55       self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.LENomPressed)
56       self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
57       self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
58       self.connect(self.bVerifie,SIGNAL("clicked()"), self.verifiePressed)
59       self.editor.affiche_infos("")
60       if self.editor.widgetOptionnel!= None :
61          self.editor.widgetOptionnel.close()
62          self.editor.widgetOptionnel=None
63
64
65
66        
67   def afficheCatalogue(self):
68       self.node.tree.racine.affichePanneau()
69       if self.node : self.node.select()
70       else : self.node.tree.racine.select()
71
72   def remplit(self):
73       nom=self.node.item.get_nom()
74       self.lineEditNom.setText(nom)
75
76       valeur=self.node.item.get_valeur()
77       if valeur == None : 
78          self.lineEditVal.clear()
79       elif type(valeur) == types.ListType :
80          texte="["
81          for l in valeur :
82            texte=texte+str(l) +","
83          texte=texte[0:-1]+"]"
84          self.lineEditVal.setText(texte)
85       else :
86          self.lineEditVal.setText(str(valeur))
87
88
89   def donnePremier(self):
90       self.lineEditVal.setFocus(7)
91
92   def LEValeurPressed(self):
93       if self.verifiePressed() == False :
94          QMessageBox.warning( self,tr( "Modification Impossible"),tr( "le parametre n'est pas valide"))
95       nom=str(self.lineEditNom.text())
96       val=str(self.lineEditVal.text())
97       self.node.item.set_nom(nom)
98       self.node.item.set_valeur(val)
99       self.node.update_texte()
100       self.node.update_node_valid()
101
102   def LENomPressed(self):
103       self.LEValeurPressed()
104
105   def verifiePressed(self):
106         nomString=str(self.lineEditNom.text())
107         if not pattern_name.match(nomString) : 
108            self.LECommentaire.setText(nomString + tr(" n est pas un identifiant correct"))
109            return False
110
111         valString=str(self.lineEditVal.text())
112
113         contexte={}
114         exec "from math import *" in contexte
115         jdc=self.node.item.get_jdc()
116         for p in jdc.params :
117            try:
118               tp=p.nom+'='+str(repr(p.valeur))
119               exec tp  in contexte
120            except exc :
121               pass
122
123         monTexte=nomString+"="+valString
124         try :
125           exec monTexte in contexte
126         except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError),  exc:
127           self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
128           return False
129         except :
130           self.LECommentaire.setText(tr("Valeur incorrecte "))
131           return False
132
133         self.LECommentaire.setText(tr("Valeur correcte "))
134         return True
135
136   def afficheApres(self):
137        self.node.selectApres()
138
139   def afficheAvant(self):
140        self.node.selectAvant()
141
142