1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 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 from __future__ import absolute_import
23 from builtins import object
27 pattern_name = re.compile(r'^[^\d\W]\w*\Z')
31 from PyQt5.QtWidgets import QDialog, QMessageBox
32 from PyQt5.QtCore import Qt
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.afficheInfos("")
43 QDialog.__init__(self,editor)
45 self.connecterSignaux()
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.connect(self.lineEditValReturnPressed)
57 self.lineEditNom.returnPressed.connect(self.lineEditNomReturnPressed)
58 self.LBParam.itemDoubleClicked.connect(self.paramClicked)
60 def paramClicked(self,item):
61 if self.editor.nodeEnCours == None :
62 QMessageBox.warning( self, tr("Pas de Mot-Clef"),tr("Attention! selectionnez un mot-clef"))
64 param= self.dictListe[item.text()]
65 self.editor.nodeEnCours.lineEditVal.setText(param)
66 self.editor.nodeEnCours.LEvaleurPressed()
69 def creeParametre(self):
70 nom=str(self.lineEditNom.text())
71 val=str(self.lineEditVal.text())
72 if val == "" or None : return
73 if nom == "" or None : return
74 if len(self.editor.tree.selectedItems()) == 0 :
75 itemAvant=self.editor.tree.racine
77 itemAvant=self.editor.tree.selectedItems()[0]
78 param=itemAvant.addParameters(True)
79 param.item.setNom(nom)
80 #PN self.val permet d entrer du texte
81 param.item.setValeur(self.val)
82 param.updateNodeTexte()
83 param.updateNodeValid()
84 self.LBParam.addItem((repr(param.item.object)))
85 self.dictListe[repr(param.item.object)] = param.item.object.nom
86 self.lineEditVal.setText("")
87 self.lineEditNom.setText("")
88 self.lineEditNom.setFocus(True)
92 def lineEditValReturnPressed(self):
93 qtVal=self.lineEditVal.text()
94 valString=str(self.lineEditVal.text())
97 exec("from math import *", contexte)
100 self.editor.afficheInfos(tr(u"La Creation de parametre n est possible que dans un jeu de donnees"),Qt.red)
103 for p in jdc.params :
105 tp=p.nom+'='+str(repr(p.valeur))
109 monTexte="monParam="+valString
111 exec(monTexte, contexte)
115 monTexte="monParam='"+valString+"'"
116 self.val="'"+valString+"'"
118 self.editor.afficheInfos(tr("Valeur incorrecte"),Qt.red)
119 if self.lineEditNom.text()!="" and self.dejaExistant==False : self.creeParametre()
122 def lineEditNomReturnPressed(self):
123 qtNom=self.lineEditNom.text()
125 if not pattern_name.match(nom) :
126 self.lineEditNom.setText("")
127 commentaire=nom + tr(" n est pas un identifiant correct\n ")
128 self.editor.afficheInfos(commentaire,Qt.red)
129 for p in self.editor.jdc.params :
131 commentaire=nom + tr(" existe deja\n ")
132 self.editor.afficheInfos(commentaire,Qt.red)
135 if self.lineEditVal.text()!="" : self.creeParametre()
136 self.lineEditVal.setFocus(Qt.OtherFocusReason)
139 def initToutesVal(self):
141 for param in self.listeTousParam :
142 self.LBParam.addItem((repr(param)))
143 self.dictListe[repr(param)] = param.nom
147 def valideParam(self):
148 if self.LBParam.selectedItems()== None : return
150 for indice in range(len(self.LBParam.selectedItems())):
151 i=self.LBParam.selectedItems()[indice].text()
152 param=self.dictListe[i]
156 self.panel.ajoutNValeur(lParam)
159 self.panel.ajout1Valeur(p)