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','CF'] : self.bCatalogue.close()
58 if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
59 elif monEnvQT5 : self.bCatalogue.clicked.connect(self.afficheCatalogue)
60 else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
63 self.lineEditVal.returnPressed.connect(self.LEValeurPressed)
64 self.lineEditNom.returnPressed.connect(self.LENomPressed)
65 self.bAvant.clicked.connect(self.afficheAvant)
66 self.bApres.clicked.connect(self.afficheApres)
67 self.bVerifie.clicked.connect(self.verifiePressed)
69 self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.LEValeurPressed)
70 self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.LENomPressed)
71 self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
72 self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
73 self.connect(self.bVerifie,SIGNAL("clicked()"), self.verifiePressed)
74 self.editor.affiche_infos("")
76 self.editor.fermeOptionnel()
79 def afficheCatalogue(self):
80 self.node.tree.racine.affichePanneau()
81 if self.node : self.node.select()
82 else : self.node.tree.racine.select()
85 nom=self.node.item.get_nom()
86 self.lineEditNom.setText(nom)
88 valeur=self.node.item.get_valeur()
90 self.lineEditVal.clear()
91 elif type(valeur) == types.ListType :
94 texte=texte+str(l) +","
96 self.lineEditVal.setText(texte)
98 self.lineEditVal.setText(str(valeur))
101 def donnePremier(self):
102 self.lineEditVal.setFocus(7)
104 def LEValeurPressed(self):
105 if self.verifiePressed() == False :
106 QMessageBox.warning( self,tr( "Modification Impossible"),tr( "le parametre n'est pas valide"))
107 nom=str(self.lineEditNom.text())
108 val=str(self.lineEditVal.text())
109 self.node.item.set_nom(nom)
110 self.node.item.set_valeur(val)
111 self.node.update_texte()
112 self.node.update_node_valid()
114 def LENomPressed(self):
115 self.LEValeurPressed()
117 def verifiePressed(self):
118 nomString=str(self.lineEditNom.text())
119 if not pattern_name.match(nomString) :
120 self.LECommentaire.setText(nomString + tr(" n est pas un identifiant correct"))
123 valString=str(self.lineEditVal.text())
126 exec "from math import *" in contexte
127 jdc=self.node.item.get_jdc()
128 for p in jdc.params :
130 tp=p.nom+'='+str(repr(p.valeur))
135 monTexte=nomString+"="+valString
137 exec monTexte in contexte
138 except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError), exc:
139 self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
142 self.LECommentaire.setText(tr("Valeur incorrecte "))
145 self.LECommentaire.setText(tr("Valeur correcte "))
148 def afficheApres(self):
149 self.node.selectApres()
151 def afficheAvant(self):
152 self.node.selectAvant()