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