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')
26 from determine import monEnvQT5
28 from PyQt5.QtWidgets import QDialog
30 from PyQt4.QtGui import *
31 from PyQt4.QtCore import *
32 from Extensions.i18n import tr
33 from desWidgetCreeParam import Ui_desWidgetCreeParam
36 class MonWidgetCreeParam(Ui_desWidgetCreeParam,QDialog):
39 def __init__(self,editor, name = None,fl = 0):
41 self.editor.affiche_infos("")
42 QDialog.__init__(self,editor)
44 if monEnvQT5 : self.connecterSignaux()
45 else : self.connecterSignauxQT4()
47 self.listeTousParam=self.editor.jdc.params
51 def connecterSignauxQT4(self) :
52 self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.lineEditValReturnPressed)
53 self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.lineEditNomReturnPressed)
55 def connecterSignaux(self) :
56 self.lineEditVal.returnPressed(self.lineEditValReturnPressed)
57 self.lineEditNom.returnPressed(self.lineEditNomReturnPressed)
59 def CreeParametre(self):
60 nom=str(self.lineEditNom.text())
61 val=str(self.lineEditVal.text())
62 if val == "" or None : return
63 if nom == "" or None : return
64 if len(self.editor.tree.selectedItems()) == 0 :
65 itemAvant=self.editor.tree.racine
67 itemAvant=self.editor.tree.selectedItems()[0]
68 param=itemAvant.addParameters(True)
69 param.item.set_nom(nom)
70 #PN self.val permet d entrer du texte
71 param.item.set_valeur(val)
72 param.update_node_texte()
73 param.update_node_valid()
74 self.LBParam.addItem(QString(repr(param.item)))
77 def lineEditValReturnPressed(self):
78 qtVal=self.lineEditVal.text()
79 valString=str(self.lineEditVal.text())
82 exec "from math import *" in contexte
85 self.editor.affiche_infos(tr(u"La Creation de parametre n est possible que dans un jeu de donnees"),Qt.red)
90 tp=p.nom+'='+str(repr(p.valeur))
94 monTexte="monParam="+valString
96 exec monTexte in contexte
100 monTexte="monParam='"+valString+"'"
101 self.val="'"+valString+"'"
103 self.editor.affiche_infos(tr("Valeur incorrecte"),Qt.red)
104 if self.lineEditNom.text()!="" and self.dejaExistant==False : self.CreeParametre()
107 def lineEditNomReturnPressed(self):
108 qtNom=self.lineEditNom.text()
110 if not pattern_name.match(nom) :
111 self.lineEditNom.setText("")
112 commentaire=nom + tr(" n est pas un identifiant correct\n ")
113 self.editor.affiche_infos(commentaire,Qt.red)
114 for p in self.editor.jdc.params :
116 commentaire=nom + tr(" existe deja\n ")
117 self.editor.affiche_infos(commentaire,Qt.red)
120 if self.lineEditVal.text()!="" : self.CreeParametre()
121 self.lineEditVal.setFocus(Qt.OtherFocusReason)
124 def initToutesVal(self):
126 for param in self.listeTousParam :
127 self.LBParam.addItem(QString(repr(param)))
128 self.dictListe[QString(repr(param))] = param
130 def valideParam(self):
131 if self.LBParam.selectedItems()== None : return
133 for indice in range(len(self.LBParam.selectedItems())):
134 i=self.LBParam.selectedItems()[indice].text()
135 param=self.dictListe[i]
139 self.panel.ajoutNValeur(lParam)
142 self.panel.ajout1Valeur(p)