Salome HOME
Pour Traduction Carmel et Parametres
[tools/eficas.git] / InterfaceQT4 / monWidgetParam.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Modules Python
21 import string,types,os,re
22
23 # Modules Eficas
24
25 from PyQt4 import *
26 from PyQt4.QtGui import *
27 from PyQt4.QtCore import *
28 from Extensions.i18n import tr
29 from desWidgetParam import Ui_desWidgetParam
30
31
32 class MonWidgetParam(Ui_desWidgetParam,QDialog):
33   """
34   """
35   def __init__(self,editor, name = None,fl = 0):
36        self.editor=editor
37        QDialog.__init__(self,editor)
38        self.setupUi(self)
39        self.connecterSignaux()
40        self.dejaExistant=0
41        self.listeTousParam=self.editor.jdc.params
42        self.dictListe={}
43        self.initToutesVal()
44
45   def connecterSignaux(self) :
46         self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.lineEditValReturnPressed)
47         self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.lineEditNomReturnPressed)
48
49
50   def CreeParametre(self):
51         nom=str(self.lineEditNom.text())
52         val=str(self.lineEditVal.text())
53         if val == "" or None : return
54         if nom == "" or None : return
55         print self.editor.tree
56         if len(self.editor.tree.selectedItems()) == 0 : itemAvant=self.editor.tree.racine 
57         else :                                          itemAvant=self.editor.tree.selectedItems()[0]
58         param=itemAvant.addParameters(True)
59         param.item.set_nom(nom)
60         param.item.set_valeur(val)
61         param.update_node_texte()
62
63
64   def lineEditValReturnPressed(self):
65         qtVal=self.lineEditVal.text()
66         valString=str(self.lineEditVal.text())
67         contexte={}
68         exec "from math import *" in contexte
69         jdc=self.editor.jdc
70         if jdc == None : 
71           self.editor.affiche_infos(tr("La Creation de parametre n est possible que dans un jeu de donnĂ©es"),Qt.red)
72           return
73
74         for p in jdc.params :
75            try:
76               tp=p.nom+'='+str(p.val)
77               exec tp  in contexte
78            except :
79               pass
80         monTexte="monParam="+valString
81         try :
82           exec monTexte in contexte
83         except :
84           self.editor.affiche_infos(tr("Valeur incorrecte"),Qt.red)
85         if self.lineEditNom.text()!="" and self.dejaExistant==False : self.CreeParametre()
86
87
88   def lineEditNomReturnPressed(self):
89         qtNom=self.lineEditNom.text()
90         nom=str(qtNom)
91         numDebutPattern=re.compile('[a-zA-Z"_"]')
92         if not (numDebutPattern.match(nom)) :
93            commentaire=tr("Les noms de parametre doivent commencer par une lettre ou un souligne")
94            self.lineEditNom.setText("")
95            self.editor.affiche_infos(commentaire,Qt.red)
96         if self.lineEditVal.text()!="" : self.CreeParametre()
97         self.lineEditVal.setFocus(Qt.OtherFocusReason)
98
99
100   def initToutesVal(self):
101         self.LBParam.clear()
102         for param in self.listeTousParam :
103             self.LBParam.addItem(QString(repr(param)))
104             self.dictListe[QString(repr(param))] = param
105
106   def valideParam(self):
107         if self.LBParam.selectedItems()== None : return
108         lParam=[]
109         for indice in range(len(self.LBParam.selectedItems())):
110             i=self.LBParam.selectedItems()[indice].text()
111             param=self.dictListe[i]
112             lParam.append(param)
113
114         try :
115           self.panel.AjoutNValeur(lParam)
116         except :
117           for p in lParam :
118              self.panel.Ajout1Valeur(p)
119         self.close()
120