Salome HOME
suite chgt copyright et menage
[tools/eficas.git] / InterfaceQT4 / monWidgetParam.py
1 # Copyright (C) 2007-2017   EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Modules Python
20 # Modules Eficas
21
22 from __future__ import absolute_import
23 try :
24    from builtins import str
25 except : pass
26
27 from desWidgetParam import Ui_WidgetParam
28 from InterfaceQT4.gereIcones import FacultatifOuOptionnel
29 import six
30 from PyQt5.QtWidgets import QWidget, QMessageBox
31 from PyQt5.QtGui import QIcon
32
33 from Extensions.i18n import tr
34 from Extensions.eficas_exception import EficasException
35 import Accas 
36 import os, re
37 import types
38
39 pattern_name       = re.compile(r'^[^\d\W]\w*\Z')
40
41     
42 # Import des panels
43
44 class MonWidgetParam(QWidget,Ui_WidgetParam,FacultatifOuOptionnel):
45   """
46   """
47   def __init__(self,node,editor,commentaire):
48       QWidget.__init__(self,None)
49       self.node=node
50       self.node.fenetre=self
51       self.setupUi(self)
52       self.editor=editor
53       self.appliEficas=self.editor.appliEficas
54       self.repIcon=self.appliEficas.repIcon
55
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)
60
61       self.remplit()
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)
65
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)
71
72       self.editor.fermeOptionnel()
73
74        
75   def afficheCatalogue(self):
76       self.node.tree.racine.affichePanneau()
77       if self.node : self.node.select()
78       else : self.node.tree.racine.select()
79
80   def remplit(self):
81       nom=self.node.item.get_nom()
82       self.lineEditNom.setText(nom)
83
84       valeur=self.node.item.get_valeur()
85       if valeur == None : 
86          self.lineEditVal.clear()
87       elif type(valeur) == list :
88          texte="["
89          for l in valeur :
90            texte=texte+str(l) +","
91          texte=texte[0:-1]+"]"
92          self.lineEditVal.setText(texte)
93       else :
94          self.lineEditVal.setText(str(valeur))
95
96
97   def donnePremier(self):
98       self.lineEditVal.setFocus(7)
99
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.set_nom(nom)
106       self.node.item.set_valeur(val)
107       self.node.update_texte()
108
109   def LENomPressed(self):
110       self.LEValeurPressed()
111
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"))
116            return False
117
118         valString=str(self.lineEditVal.text())
119
120         contexte={}
121         exec("from math import *", contexte)
122         jdc=self.node.item.get_jdc()
123         for p in jdc.params :
124            try:
125               tp=p.nom+'='+str(repr(p.valeur))
126               exec(tp, contexte)
127            except exc :
128               pass
129
130         monTexte=nomString+"="+valString
131         try :
132           exec(monTexte, contexte)
133         except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError) as  exc:
134           self.LECommentaire.setText(tr("Valeur incorrecte: ")+six.text_type (exc))
135           return False
136         except :
137           self.LECommentaire.setText(tr("Valeur incorrecte "))
138           return False
139
140         self.LECommentaire.setText(tr("Valeur correcte "))
141         return True
142
143   def afficheApres(self):
144        self.node.selectApres()
145
146   def afficheAvant(self):
147        self.node.selectAvant()
148
149