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.appliEficas=self.editor.appliEficas
48 self.repIcon=self.appliEficas.repIcon
50 self.setIconePoubelle()
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
67 def afficheCatalogue(self):
68 self.node.tree.racine.affichePanneau()
69 if self.node : self.node.select()
70 else : self.node.tree.racine.select()
73 nom=self.node.item.get_nom()
74 self.lineEditNom.setText(nom)
76 valeur=self.node.item.get_valeur()
78 self.lineEditVal.clear()
79 elif type(valeur) == types.ListType :
82 texte=texte+str(l) +","
84 self.lineEditVal.setText(texte)
86 self.lineEditVal.setText(str(valeur))
89 def donnePremier(self):
90 self.lineEditVal.setFocus(7)
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()
102 def LENomPressed(self):
103 self.LEValeurPressed()
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"))
111 valString=str(self.lineEditVal.text())
114 exec "from math import *" in contexte
115 jdc=self.node.item.get_jdc()
116 for p in jdc.params :
118 tp=p.nom+'='+str(repr(p.valeur))
123 monTexte=nomString+"="+valString
125 exec monTexte in contexte
126 except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError), exc:
127 self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
130 self.LECommentaire.setText(tr("Valeur incorrecte "))
133 self.LECommentaire.setText(tr("Valeur correcte "))
136 def afficheApres(self):
137 self.node.selectApres()
139 def afficheAvant(self):
140 self.node.selectAvant()