]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/monWidgetParam.py
Salome HOME
chgt Copyrigth
[tools/eficas.git] / InterfaceQT4 / monWidgetParam.py
1 # Copyright (C) 2007-2021   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 from PyQt5.QtWidgets import QWidget, QMessageBox
30 from PyQt5.QtGui import QIcon
31
32 from Extensions.i18n import tr
33 from Extensions.eficas_exception import EficasException
34 import Accas 
35 import os, re
36 import types
37
38 pattern_name       = re.compile(r'^[^\d\W]\w*\Z')
39
40     
41 # Import des panels
42
43 class MonWidgetParam(QWidget,Ui_WidgetParam,FacultatifOuOptionnel):
44   """
45   """
46   def __init__(self,node,editor,commentaire):
47       QWidget.__init__(self,None)
48       self.node=node
49       self.node.fenetre=self
50       self.setupUi(self)
51       self.editor=editor
52       self.appliEficas=self.editor.appliEficas
53       self.repIcon=self.appliEficas.repIcon
54
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)
59
60       self.remplit()
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)
64
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)
70
71       self.editor.fermeOptionnel()
72
73        
74   def afficheCatalogue(self):
75       self.node.tree.racine.affichePanneau()
76       if self.node : self.node.select()
77       else : self.node.tree.racine.select()
78
79   def remplit(self):
80       nom=self.node.item.getNom()
81       self.lineEditNom.setText(nom)
82
83       valeur=self.node.item.getValeur()
84       if valeur == None : 
85          self.lineEditVal.clear()
86       elif type(valeur) == list :
87          texte="["
88          for l in valeur :
89            texte=texte+str(l) +","
90          texte=texte[0:-1]+"]"
91          self.lineEditVal.setText(texte)
92       else :
93          self.lineEditVal.setText(str(valeur))
94
95
96   def donnePremier(self):
97       self.lineEditVal.setFocus(7)
98
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()
107
108   def LENomPressed(self):
109       self.LEvaleurPressed()
110
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"))
115            return False
116
117         valString=str(self.lineEditVal.text())
118
119         contexte={}
120         exec("from math import *", contexte)
121         jdc=self.node.item.getJdc()
122         for p in jdc.params :
123            try:
124               tp=p.nom+'='+str(repr(p.valeur))
125               exec(tp, contexte)
126            except exc :
127               pass
128
129         monTexte=nomString+"="+valString
130         try :
131           exec(monTexte, contexte)
132         except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError) as  exc:
133           self.LECommentaire.setText(tr("Valeur incorrecte: ")+str(exc))
134           return False
135         except :
136           self.LECommentaire.setText(tr("Valeur incorrecte "))
137           return False
138
139         self.LECommentaire.setText(tr("Valeur correcte "))
140         return True
141
142   def afficheApres(self):
143        self.node.selectApres()
144
145   def afficheAvant(self):
146        self.node.selectAvant()
147
148