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
29 from PyQt5.QtCore import Qt
31 from PyQt4.QtGui import *
32 from PyQt4.QtCore import *
33 from Extensions.i18n import tr
34 from desWidgetCreeParam import Ui_desWidgetCreeParam
37 class MonWidgetCreeParam(Ui_desWidgetCreeParam,QDialog):
40 def __init__(self,editor, name = None,fl = 0):
42 self.editor.affiche_infos("")
43 QDialog.__init__(self,editor)
45 if monEnvQT5 : self.connecterSignaux()
46 else : self.connecterSignauxQT4()
48 self.listeTousParam=self.editor.jdc.params
52 def connecterSignauxQT4(self) :
53 self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.lineEditValReturnPressed)
54 self.connect(self.lineEditNom,SIGNAL("returnPressed()"),self.lineEditNomReturnPressed)
56 def connecterSignaux(self) :
57 self.lineEditVal.returnPressed.connect(self.lineEditValReturnPressed)
58 self.lineEditNom.returnPressed.connect(self.lineEditNomReturnPressed)
60 def CreeParametre(self):
61 nom=str(self.lineEditNom.text())
62 val=str(self.lineEditVal.text())
63 if val == "" or None : return
64 if nom == "" or None : return
65 if len(self.editor.tree.selectedItems()) == 0 :
66 itemAvant=self.editor.tree.racine
68 itemAvant=self.editor.tree.selectedItems()[0]
69 param=itemAvant.addParameters(True)
70 param.item.set_nom(nom)
71 #PN self.val permet d entrer du texte
72 param.item.set_valeur(self.val)
73 param.update_node_texte()
74 param.update_node_valid()
75 self.LBParam.addItem((repr(param.item)))
77 self.lineEditVal.setText("")
78 self.lineEditNom.setText("")
79 self.lineEditNom.setFocus(True)
83 def lineEditValReturnPressed(self):
84 qtVal=self.lineEditVal.text()
85 valString=str(self.lineEditVal.text())
88 exec "from math import *" in contexte
91 self.editor.affiche_infos(tr(u"La Creation de parametre n est possible que dans un jeu de donnees"),Qt.red)
96 tp=p.nom+'='+str(repr(p.valeur))
100 monTexte="monParam="+valString
102 exec monTexte in contexte
106 monTexte="monParam='"+valString+"'"
107 self.val="'"+valString+"'"
109 self.editor.affiche_infos(tr("Valeur incorrecte"),Qt.red)
110 if self.lineEditNom.text()!="" and self.dejaExistant==False : self.CreeParametre()
113 def lineEditNomReturnPressed(self):
114 qtNom=self.lineEditNom.text()
116 if not pattern_name.match(nom) :
117 self.lineEditNom.setText("")
118 commentaire=nom + tr(" n est pas un identifiant correct\n ")
119 self.editor.affiche_infos(commentaire,Qt.red)
120 for p in self.editor.jdc.params :
122 commentaire=nom + tr(" existe deja\n ")
123 self.editor.affiche_infos(commentaire,Qt.red)
126 if self.lineEditVal.text()!="" : self.CreeParametre()
127 self.lineEditVal.setFocus(Qt.OtherFocusReason)
130 def initToutesVal(self):
132 for param in self.listeTousParam :
133 self.LBParam.addItem((repr(param)))
134 self.dictListe[repr(param)] = param
136 def valideParam(self):
137 if self.LBParam.selectedItems()== None : return
139 for indice in range(len(self.LBParam.selectedItems())):
140 i=self.LBParam.selectedItems()[indice].text()
141 param=self.dictListe[i]
145 self.panel.ajoutNValeur(lParam)
148 self.panel.ajout1Valeur(p)