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, QMessageBox
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("")
75 self.editor.fermeOptionnel()
78 def afficheCatalogue(self):
79 self.node.tree.racine.affichePanneau()
80 if self.node : self.node.select()
81 else : self.node.tree.racine.select()
84 nom=self.node.item.get_nom()
85 self.lineEditNom.setText(nom)
87 valeur=self.node.item.get_valeur()
89 self.lineEditVal.clear()
90 elif type(valeur) == types.ListType :
93 texte=texte+str(l) +","
95 self.lineEditVal.setText(texte)
97 self.lineEditVal.setText(str(valeur))
100 def donnePremier(self):
101 self.lineEditVal.setFocus(7)
103 def LEValeurPressed(self):
104 if self.verifiePressed() == False :
105 QMessageBox.warning( self,tr( "Modification Impossible"),tr( "le parametre n'est pas valide"))
106 nom=str(self.lineEditNom.text())
107 val=str(self.lineEditVal.text())
108 self.node.item.set_nom(nom)
109 self.node.item.set_valeur(val)
110 self.node.update_texte()
111 self.node.update_node_valid()
113 def LENomPressed(self):
114 self.LEValeurPressed()
116 def verifiePressed(self):
117 nomString=str(self.lineEditNom.text())
118 if not pattern_name.match(nomString) :
119 self.LECommentaire.setText(nomString + tr(" n est pas un identifiant correct"))
122 valString=str(self.lineEditVal.text())
125 exec "from math import *" in contexte
126 jdc=self.node.item.get_jdc()
127 for p in jdc.params :
129 tp=p.nom+'='+str(repr(p.valeur))
134 monTexte=nomString+"="+valString
136 exec monTexte in contexte
137 except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError), exc:
138 self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
141 self.LECommentaire.setText(tr("Valeur incorrecte "))
144 self.LECommentaire.setText(tr("Valeur correcte "))
147 def afficheApres(self):
148 self.node.selectApres()
150 def afficheAvant(self):
151 self.node.selectAvant()