1 # Copyright (C) 2007-2021 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 __future__ import absolute_import
24 from builtins import str
27 from desWidgetParam import Ui_WidgetParam
28 from InterfaceQT4.gereIcones import FacultatifOuOptionnel
29 from PyQt5.QtWidgets import QWidget, QMessageBox
30 from PyQt5.QtGui import QIcon
32 from Extensions.i18n import tr
33 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()
56 if not(self.node.item.object.isValid()) :
57 icon=QIcon(self.repIcon+"/ast-red-ball.png")
58 self.RBValide.setIcon(icon)
61 #if self.editor.code in ['MAP','CARMELCND','CF'] : self.bCatalogue.close()
62 if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
63 else : self.bCatalogue.clicked.connect(self.afficheCatalogue)
65 self.lineEditVal.returnPressed.connect(self.LEvaleurPressed)
66 self.lineEditNom.returnPressed.connect(self.LENomPressed)
67 self.bAvant.clicked.connect(self.afficheAvant)
68 self.bApres.clicked.connect(self.afficheApres)
69 self.bVerifie.clicked.connect(self.verifiePressed)
71 self.editor.fermeOptionnel()
74 def afficheCatalogue(self):
75 self.node.tree.racine.affichePanneau()
76 if self.node : self.node.select()
77 else : self.node.tree.racine.select()
80 nom=self.node.item.getNom()
81 self.lineEditNom.setText(nom)
83 valeur=self.node.item.getValeur()
85 self.lineEditVal.clear()
86 elif type(valeur) == list :
89 texte=texte+str(l) +","
91 self.lineEditVal.setText(texte)
93 self.lineEditVal.setText(str(valeur))
96 def donnePremier(self):
97 self.lineEditVal.setFocus(7)
99 def LEvaleurPressed(self):
100 if self.verifiePressed() == False :
101 QMessageBox.warning( self,tr( "Modification Impossible"),tr( "le parametre n'est pas valide"))
102 nom=str(self.lineEditNom.text())
103 val=str(self.lineEditVal.text())
104 self.node.item.setNom(nom)
105 self.node.item.setValeur(val)
106 self.node.updateTexte()
108 def LENomPressed(self):
109 self.LEvaleurPressed()
111 def verifiePressed(self):
112 nomString=str(self.lineEditNom.text())
113 if not pattern_name.match(nomString) :
114 self.LECommentaire.setText(nomString + tr(" n est pas un identifiant correct"))
117 valString=str(self.lineEditVal.text())
120 exec("from math import *", contexte)
121 jdc=self.node.item.getJdc()
122 for p in jdc.params :
124 tp=p.nom+'='+str(repr(p.valeur))
129 monTexte=nomString+"="+valString
131 exec(monTexte, contexte)
132 except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError) as exc:
133 self.LECommentaire.setText(tr("Valeur incorrecte: ")+str(exc))
136 self.LECommentaire.setText(tr("Valeur incorrecte "))
139 self.LECommentaire.setText(tr("Valeur correcte "))
142 def afficheApres(self):
143 self.node.selectApres()
145 def afficheAvant(self):
146 self.node.selectAvant()