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 determine import monEnvQT5
26 from PyQt5.QtWidgets import QWidget
28 from PyQt4.QtGui import *
29 from PyQt4.QtCore import *
31 from Extensions.i18n import tr
32 from Extensions.eficas_exception import EficasException
38 pattern_name = re.compile(r'^[^\d\W]\w*\Z')
43 class MonWidgetParam(QWidget,Ui_WidgetParam,FacultatifOuOptionnel):
46 def __init__(self,node,editor,commentaire):
47 QWidget.__init__(self,None)
49 self.node.fenetre=self
52 self.appliEficas=self.editor.appliEficas
53 self.repIcon=self.appliEficas.repIcon
55 self.setIconePoubelle()
57 if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
58 elif monEnvQt5 : self.bCatalogue.clicked.connect(self.afficheCatalogue)
59 else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
62 self.lineEditVal.returnPressed.connect.(self.LEValeurPressed)
63 self.lineEditNom.returnPressed.connect.(self.LENomPressed)
64 self.bAvant.clicked.connect.(self.afficheAvant)
65 self.bApres.clicked.connect.(self.afficheApres)
66 self.bVerifie.clicked.connect.(self.verifiePressed)
68 self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.LEValeurPressed)
69 self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.LENomPressed)
70 self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
71 self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
72 self.connect(self.bVerifie,SIGNAL("clicked()"), self.verifiePressed)
73 self.editor.affiche_infos("")
76 if self.editor.widgetOptionnel!= None :
77 self.editor.widgetOptionnel.close()
78 self.editor.widgetOptionnel=None
83 def afficheCatalogue(self):
84 self.node.tree.racine.affichePanneau()
85 if self.node : self.node.select()
86 else : self.node.tree.racine.select()
89 nom=self.node.item.get_nom()
90 self.lineEditNom.setText(nom)
92 valeur=self.node.item.get_valeur()
94 self.lineEditVal.clear()
95 elif type(valeur) == types.ListType :
98 texte=texte+str(l) +","
100 self.lineEditVal.setText(texte)
102 self.lineEditVal.setText(str(valeur))
105 def donnePremier(self):
106 self.lineEditVal.setFocus(7)
108 def LEValeurPressed(self):
109 if self.verifiePressed() == False :
110 QMessageBox.warning( self,tr( "Modification Impossible"),tr( "le parametre n'est pas valide"))
111 nom=str(self.lineEditNom.text())
112 val=str(self.lineEditVal.text())
113 self.node.item.set_nom(nom)
114 self.node.item.set_valeur(val)
115 self.node.update_texte()
116 self.node.update_node_valid()
118 def LENomPressed(self):
119 self.LEValeurPressed()
121 def verifiePressed(self):
122 nomString=str(self.lineEditNom.text())
123 if not pattern_name.match(nomString) :
124 self.LECommentaire.setText(nomString + tr(" n est pas un identifiant correct"))
127 valString=str(self.lineEditVal.text())
130 exec "from math import *" in contexte
131 jdc=self.node.item.get_jdc()
132 for p in jdc.params :
134 tp=p.nom+'='+str(repr(p.valeur))
139 monTexte=nomString+"="+valString
141 exec monTexte in contexte
142 except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError), exc:
143 self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
146 self.LECommentaire.setText(tr("Valeur incorrecte "))
149 self.LECommentaire.setText(tr("Valeur correcte "))
152 def afficheApres(self):
153 self.node.selectApres()
155 def afficheAvant(self):
156 self.node.selectAvant()