1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 import string,types,os,re
26 from PyQt4.QtGui import *
27 from PyQt4.QtCore import *
28 from Extensions.i18n import tr
29 from desWidgetParam import Ui_desWidgetParam
32 class MonWidgetParam(Ui_desWidgetParam,QDialog):
35 def __init__(self,editor, name = None,fl = 0):
37 QDialog.__init__(self,editor)
39 self.connecterSignaux()
41 self.listeTousParam=self.editor.jdc.params
45 def connecterSignaux(self) :
46 self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.lineEditValReturnPressed)
47 self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.lineEditNomReturnPressed)
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 :
57 itemAvant=self.editor.tree.racine
58 param=itemAvant.addParameters(True)
60 itemAvant=self.editor.tree.selectedItems()[0]
61 param=itemAvant.addParameters(False)
62 param.item.set_nom(nom)
63 param.item.set_valeur(val)
64 param.update_node_texte()
67 def lineEditValReturnPressed(self):
68 qtVal=self.lineEditVal.text()
69 valString=str(self.lineEditVal.text())
71 exec "from math import *" in contexte
74 self.editor.affiche_infos(tr("La Creation de parametre n est possible que dans un jeu de données"),Qt.red)
79 tp=p.nom+'='+str(p.val)
83 monTexte="monParam="+valString
85 exec monTexte in contexte
87 self.editor.affiche_infos(tr("Valeur incorrecte"),Qt.red)
88 if self.lineEditNom.text()!="" and self.dejaExistant==False : self.CreeParametre()
91 def lineEditNomReturnPressed(self):
92 qtNom=self.lineEditNom.text()
94 numDebutPattern=re.compile('[a-zA-Z"_"]')
95 if not (numDebutPattern.match(nom)) :
96 commentaire=tr("Les noms de parametre doivent commencer par une lettre ou un souligne")
97 self.lineEditNom.setText("")
98 self.editor.affiche_infos(commentaire,Qt.red)
99 if self.lineEditVal.text()!="" : self.CreeParametre()
100 self.lineEditVal.setFocus(Qt.OtherFocusReason)
103 def initToutesVal(self):
105 for param in self.listeTousParam :
106 self.LBParam.addItem(QString(repr(param)))
107 self.dictListe[QString(repr(param))] = param
109 def valideParam(self):
110 if self.LBParam.selectedItems()== None : return
112 for indice in range(len(self.LBParam.selectedItems())):
113 i=self.LBParam.selectedItems()[indice].text()
114 param=self.dictListe[i]
118 self.panel.AjoutNValeur(lParam)
121 self.panel.Ajout1Valeur(p)