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