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("")
57 if self.editor.widgetOptionnel!= None :
58 self.editor.widgetOptionnel.close()
59 self.editor.widgetOptionnel=None
64 def afficheCatalogue(self):
65 self.node.tree.racine.affichePanneau()
66 if self.node : self.node.select()
67 else : self.node.tree.racine.select()
70 nom=self.node.item.get_nom()
71 self.lineEditNom.setText(nom)
73 valeur=self.node.item.get_valeur()
75 self.lineEditVal.clear()
76 elif type(valeur) == types.ListType :
79 texte=texte+str(l) +","
81 self.lineEditVal.setText(texte)
83 self.lineEditVal.setText(str(valeur))
86 def donnePremier(self):
87 self.lineEditVal.setFocus(7)
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()
99 def LENomPressed(self):
100 self.LEValeurPressed()
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"))
108 valString=str(self.lineEditVal.text())
111 exec "from math import *" in contexte
112 jdc=self.node.item.get_jdc()
113 for p in jdc.params :
115 tp=p.nom+'='+str(repr(p.valeur))
120 monTexte=nomString+"="+valString
122 exec monTexte in contexte
123 except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError), exc:
124 self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
127 self.LECommentaire.setText(tr("Valeur incorrecte "))
130 self.LECommentaire.setText(tr("Valeur correcte "))
133 def afficheApres(self):
134 self.node.selectApres()
136 def afficheAvant(self):
137 self.node.selectAvant()