1 # Copyright (C) 2007-2017 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
30 from PyQt5.QtWidgets import QWidget, QMessageBox
31 from PyQt5.QtGui import QIcon
33 from Extensions.i18n import tr
34 from Extensions.eficas_exception import EficasException
39 pattern_name = re.compile(r'^[^\d\W]\w*\Z')
44 class MonWidgetParam(QWidget,Ui_WidgetParam,FacultatifOuOptionnel):
47 def __init__(self,node,editor,commentaire):
48 QWidget.__init__(self,None)
50 self.node.fenetre=self
53 self.appliEficas=self.editor.appliEficas
54 self.repIcon=self.appliEficas.repIcon
56 self.setIconePoubelle()
57 if not(self.node.item.object.isValid()) :
58 icon=QIcon(self.repIcon+"/ast-red-ball.png")
59 self.RBValide.setIcon(icon)
62 #if self.editor.code in ['MAP','CARMELCND','CF'] : self.bCatalogue.close()
63 if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
64 else : self.bCatalogue.clicked.connect(self.afficheCatalogue)
66 self.lineEditVal.returnPressed.connect(self.LEvaleurPressed)
67 self.lineEditNom.returnPressed.connect(self.LENomPressed)
68 self.bAvant.clicked.connect(self.afficheAvant)
69 self.bApres.clicked.connect(self.afficheApres)
70 self.bVerifie.clicked.connect(self.verifiePressed)
72 self.editor.fermeOptionnel()
75 def afficheCatalogue(self):
76 self.node.tree.racine.affichePanneau()
77 if self.node : self.node.select()
78 else : self.node.tree.racine.select()
81 nom=self.node.item.getNom()
82 self.lineEditNom.setText(nom)
84 valeur=self.node.item.getValeur()
86 self.lineEditVal.clear()
87 elif type(valeur) == list :
90 texte=texte+str(l) +","
92 self.lineEditVal.setText(texte)
94 self.lineEditVal.setText(str(valeur))
97 def donnePremier(self):
98 self.lineEditVal.setFocus(7)
100 def LEvaleurPressed(self):
101 if self.verifiePressed() == False :
102 QMessageBox.warning( self,tr( "Modification Impossible"),tr( "le parametre n'est pas valide"))
103 nom=str(self.lineEditNom.text())
104 val=str(self.lineEditVal.text())
105 self.node.item.setNom(nom)
106 self.node.item.setValeur(val)
107 self.node.updateTexte()
109 def LENomPressed(self):
110 self.LEvaleurPressed()
112 def verifiePressed(self):
113 nomString=str(self.lineEditNom.text())
114 if not pattern_name.match(nomString) :
115 self.LECommentaire.setText(nomString + tr(" n est pas un identifiant correct"))
118 valString=str(self.lineEditVal.text())
121 exec("from math import *", contexte)
122 jdc=self.node.item.getJdc()
123 for p in jdc.params :
125 tp=p.nom+'='+str(repr(p.valeur))
130 monTexte=nomString+"="+valString
132 exec(monTexte, contexte)
133 except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError) as exc:
134 self.LECommentaire.setText(tr("Valeur incorrecte: ")+six.text_type (exc))
137 self.LECommentaire.setText(tr("Valeur incorrecte "))
140 self.LECommentaire.setText(tr("Valeur correcte "))
143 def afficheApres(self):
144 self.node.selectApres()
146 def afficheAvant(self):
147 self.node.selectAvant()