1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017 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 from six.moves import range
28 pattern_name = re.compile(r'^[^\d\W]\w*\Z')
32 from PyQt5.QtWidgets import QDialog, QMessageBox
33 from PyQt5.QtCore import Qt
34 from Extensions.i18n import tr
35 from desWidgetCreeParam import Ui_desWidgetCreeParam
38 class MonWidgetCreeParam(Ui_desWidgetCreeParam,QDialog):
41 def __init__(self,editor, name = None,fl = 0):
43 self.editor.affiche_infos("")
44 QDialog.__init__(self,editor)
46 self.connecterSignaux()
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)
59 self.LBParam.itemDoubleClicked.connect(self.paramClicked)
61 def paramClicked(self,item):
62 if self.editor.nodeEnCours == None :
63 QMessageBox.warning( self, tr("Pas de Mot-Clef"),tr("Attention! selectionnez un mot-clef"))
65 param= self.dictListe[item.text()]
66 self.editor.nodeEnCours.lineEditVal.setText(param)
67 self.editor.nodeEnCours.LEValeurPressed()
70 def CreeParametre(self):
71 nom=str(self.lineEditNom.text())
72 val=str(self.lineEditVal.text())
73 if val == "" or None : return
74 if nom == "" or None : return
75 if len(self.editor.tree.selectedItems()) == 0 :
76 itemAvant=self.editor.tree.racine
78 itemAvant=self.editor.tree.selectedItems()[0]
79 param=itemAvant.addParameters(True)
80 param.item.set_nom(nom)
81 #PN self.val permet d entrer du texte
82 param.item.set_valeur(self.val)
83 param.update_node_texte()
84 param.update_node_valid()
85 self.LBParam.addItem((repr(param.item.object)))
86 self.dictListe[repr(param.item.object)] = param.item.object.nom
87 self.lineEditVal.setText("")
88 self.lineEditNom.setText("")
89 self.lineEditNom.setFocus(True)
93 def lineEditValReturnPressed(self):
94 qtVal=self.lineEditVal.text()
95 valString=str(self.lineEditVal.text())
98 exec("from math import *", contexte)
101 self.editor.affiche_infos(tr(u"La Creation de parametre n est possible que dans un jeu de donnees"),Qt.red)
104 for p in jdc.params :
106 tp=p.nom+'='+str(repr(p.valeur))
110 monTexte="monParam="+valString
112 exec(monTexte, contexte)
116 monTexte="monParam='"+valString+"'"
117 self.val="'"+valString+"'"
119 self.editor.affiche_infos(tr("Valeur incorrecte"),Qt.red)
120 if self.lineEditNom.text()!="" and self.dejaExistant==False : self.CreeParametre()
123 def lineEditNomReturnPressed(self):
124 qtNom=self.lineEditNom.text()
126 if not pattern_name.match(nom) :
127 self.lineEditNom.setText("")
128 commentaire=nom + tr(" n est pas un identifiant correct\n ")
129 self.editor.affiche_infos(commentaire,Qt.red)
130 for p in self.editor.jdc.params :
132 commentaire=nom + tr(" existe deja\n ")
133 self.editor.affiche_infos(commentaire,Qt.red)
136 if self.lineEditVal.text()!="" : self.CreeParametre()
137 self.lineEditVal.setFocus(Qt.OtherFocusReason)
140 def initToutesVal(self):
142 for param in self.listeTousParam :
143 self.LBParam.addItem((repr(param)))
144 self.dictListe[repr(param)] = param.nom
148 def valideParam(self):
149 if self.LBParam.selectedItems()== None : return
151 for indice in range(len(self.LBParam.selectedItems())):
152 i=self.LBParam.selectedItems()[indice].text()
153 param=self.dictListe[i]
157 self.panel.ajoutNValeur(lParam)
160 self.panel.ajout1Valeur(p)