1 # Copyright (C) 2007-2013 EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
33 pattern_name = re.compile(r'^[^\d\W]\w*\Z')
38 class MonWidgetParam(QWidget,Ui_WidgetParam,FacultatifOuOptionnel):
41 def __init__(self,node,editor,commentaire):
42 QWidget.__init__(self,None)
44 self.node.fenetre=self
47 self.setIconePoubelle()
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("")
60 def afficheCatalogue(self):
61 self.node.tree.racine.affichePanneau()
62 if self.node : self.node.select()
63 else : self.node.tree.racine.select()
66 nom=self.node.item.get_nom()
67 self.lineEditNom.setText(nom)
69 valeur=self.node.item.get_valeur()
71 self.lineEditVal.clear()
72 elif type(valeur) == types.ListType :
75 texte=texte+str(l) +","
77 self.lineEditVal.setText(texte)
79 self.lineEditVal.setText(str(valeur))
82 def donnePremier(self):
83 self.lineEditVal.setFocus(7)
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()
95 def LENomPressed(self):
96 self.LEValeurPressed()
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"))
104 valString=str(self.lineEditVal.text())
107 exec "from math import *" in contexte
108 jdc=self.node.item.get_jdc()
109 for p in jdc.params :
111 tp=p.nom+'='+str(repr(p.valeur))
116 monTexte=nomString+"="+valString
118 exec monTexte in contexte
119 except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError), exc:
120 self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
123 self.LECommentaire.setText(tr("Valeur incorrecte "))
126 self.LECommentaire.setText(tr("Valeur correcte "))
129 def afficheApres(self):
130 self.node.selectApres()
132 def afficheAvant(self):
133 self.node.selectAvant()