Salome HOME
0190e530e7275b5bb9cf34e48cffe60e40f0e04b
[tools/eficas.git] / InterfaceQT4 / monWidgetParam.py
1 # Copyright (C) 2007-2013   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 desWidgetParam import Ui_WidgetParam
23 from gereIcones import FacultatifOuOptionnel
24 from determine import monEnvQT5
25 if monEnvQT5:
26     from PyQt5.QtWidgets import QWidget, QMessageBox
27 else :
28     from PyQt4.QtGui  import *
29     from PyQt4.QtCore import *
30
31 from Extensions.i18n import tr
32 from Extensions.eficas_exception import EficasException
33 import Accas 
34 import os, re
35 import string
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       self.remplit()
57       if self.editor.code in ['MAP','CARMELCND'] : self.bCatalogue.close()
58       elif monEnvQT5 : self.bCatalogue.clicked.connect(self.afficheCatalogue)
59       else : self.connect(self.bCatalogue,SIGNAL("clicked()"), self.afficheCatalogue)
60
61       if monEnvQT5 :
62         self.lineEditVal.returnPressed.connect(self.LEValeurPressed)
63         self.lineEditNom.returnPressed.connect(self.LENomPressed)
64         self.bAvant.clicked.connect(self.afficheAvant)
65         self.bApres.clicked.connect(self.afficheApres)
66         self.bVerifie.clicked.connect(self.verifiePressed)
67       else :
68         self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.LEValeurPressed)
69         self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.LENomPressed)
70         self.connect(self.bAvant,SIGNAL("clicked()"), self.afficheAvant)
71         self.connect(self.bApres,SIGNAL("clicked()"), self.afficheApres)
72         self.connect(self.bVerifie,SIGNAL("clicked()"), self.verifiePressed)
73         self.editor.affiche_infos("")
74
75       self.editor.fermeOptionnel()
76
77        
78   def afficheCatalogue(self):
79       self.node.tree.racine.affichePanneau()
80       if self.node : self.node.select()
81       else : self.node.tree.racine.select()
82
83   def remplit(self):
84       nom=self.node.item.get_nom()
85       self.lineEditNom.setText(nom)
86
87       valeur=self.node.item.get_valeur()
88       if valeur == None : 
89          self.lineEditVal.clear()
90       elif type(valeur) == types.ListType :
91          texte="["
92          for l in valeur :
93            texte=texte+str(l) +","
94          texte=texte[0:-1]+"]"
95          self.lineEditVal.setText(texte)
96       else :
97          self.lineEditVal.setText(str(valeur))
98
99
100   def donnePremier(self):
101       self.lineEditVal.setFocus(7)
102
103   def LEValeurPressed(self):
104       if self.verifiePressed() == False :
105          QMessageBox.warning( self,tr( "Modification Impossible"),tr( "le parametre n'est pas valide"))
106       nom=str(self.lineEditNom.text())
107       val=str(self.lineEditVal.text())
108       self.node.item.set_nom(nom)
109       self.node.item.set_valeur(val)
110       self.node.update_texte()
111       self.node.update_node_valid()
112
113   def LENomPressed(self):
114       self.LEValeurPressed()
115
116   def verifiePressed(self):
117         nomString=str(self.lineEditNom.text())
118         if not pattern_name.match(nomString) : 
119            self.LECommentaire.setText(nomString + tr(" n est pas un identifiant correct"))
120            return False
121
122         valString=str(self.lineEditVal.text())
123
124         contexte={}
125         exec "from math import *" in contexte
126         jdc=self.node.item.get_jdc()
127         for p in jdc.params :
128            try:
129               tp=p.nom+'='+str(repr(p.valeur))
130               exec tp  in contexte
131            except exc :
132               pass
133
134         monTexte=nomString+"="+valString
135         try :
136           exec monTexte in contexte
137         except (ValueError,TypeError, NameError,RuntimeError,ZeroDivisionError),  exc:
138           self.LECommentaire.setText(tr("Valeur incorrecte: ")+unicode (exc))
139           return False
140         except :
141           self.LECommentaire.setText(tr("Valeur incorrecte "))
142           return False
143
144         self.LECommentaire.setText(tr("Valeur correcte "))
145         return True
146
147   def afficheApres(self):
148        self.node.selectApres()
149
150   def afficheAvant(self):
151        self.node.selectAvant()
152
153