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
22 pattern_name = re.compile(r'^[^\d\W]\w*\Z')
27 from PyQt4.QtGui import *
28 from PyQt4.QtCore import *
29 from Extensions.i18n import tr
30 from desWidgetCreeParam import Ui_desWidgetCreeParam
33 class MonWidgetCreeParam(Ui_desWidgetCreeParam,QDialog):
36 def __init__(self,editor, name = None,fl = 0):
38 self.editor.affiche_infos("")
39 QDialog.__init__(self,editor)
41 self.connecterSignaux()
43 self.listeTousParam=self.editor.jdc.params
47 def connecterSignaux(self) :
48 self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.lineEditValReturnPressed)
49 self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.lineEditNomReturnPressed)
52 def CreeParametre(self):
53 nom=str(self.lineEditNom.text())
54 val=str(self.lineEditVal.text())
55 if val == "" or None : return
56 if nom == "" or None : return
57 if len(self.editor.tree.selectedItems()) == 0 :
58 itemAvant=self.editor.tree.racine
60 itemAvant=self.editor.tree.selectedItems()[0]
61 param=itemAvant.addParameters(True)
62 param.item.set_nom(nom)
63 #PN self.val permet d entrer du texte
64 param.item.set_valeur(val)
65 param.update_node_texte()
66 param.update_node_valid()
67 self.LBParam.addItem(QString(repr(param.item)))
70 def lineEditValReturnPressed(self):
71 qtVal=self.lineEditVal.text()
72 valString=str(self.lineEditVal.text())
75 exec "from math import *" in contexte
78 self.editor.affiche_infos(tr(u"La Creation de parametre n est possible que dans un jeu de donnees"),Qt.red)
83 tp=p.nom+'='+str(repr(p.valeur))
87 monTexte="monParam="+valString
89 exec monTexte in contexte
93 monTexte="monParam='"+valString+"'"
94 self.val="'"+valString+"'"
96 self.editor.affiche_infos(tr("Valeur incorrecte"),Qt.red)
97 if self.lineEditNom.text()!="" and self.dejaExistant==False : self.CreeParametre()
100 def lineEditNomReturnPressed(self):
101 qtNom=self.lineEditNom.text()
103 if not pattern_name.match(nom) :
104 self.lineEditNom.setText("")
105 commentaire=nom + tr(" n est pas un identifiant correct\n ")
106 self.editor.affiche_infos(commentaire,Qt.red)
107 for p in self.editor.jdc.params :
109 commentaire=nom + tr(" existe deja\n ")
110 self.editor.affiche_infos(commentaire,Qt.red)
113 if self.lineEditVal.text()!="" : self.CreeParametre()
114 self.lineEditVal.setFocus(Qt.OtherFocusReason)
117 def initToutesVal(self):
119 for param in self.listeTousParam :
120 self.LBParam.addItem(QString(repr(param)))
121 self.dictListe[QString(repr(param))] = param
123 def valideParam(self):
124 if self.LBParam.selectedItems()== None : return
126 for indice in range(len(self.LBParam.selectedItems())):
127 i=self.LBParam.selectedItems()[indice].text()
128 param=self.dictListe[i]
132 self.panel.ajoutNValeur(lParam)
135 self.panel.ajout1Valeur(p)