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 str
24 from builtins import range
25 from builtins import object
30 from six.moves import range
31 from PyQt5.QtWidgets import QFrame,QApplication, QFrame, QWidget
32 from PyQt5.QtGui import QIcon
33 from PyQt5.QtCore import QSize, Qt, QTimer
35 from Extensions.i18n import tr
38 from InterfaceQT4.feuille import Feuille
39 from InterfaceQT4.politiquesValidation import PolitiquePlusieurs
40 from InterfaceQT4.qtSaisie import SaisieValeur
41 from InterfaceQT4.gereListe import GereListe
42 from InterfaceQT4.gereListe import LECustom
43 from Tuple2 import Ui_Tuple2
44 from Tuple3 import Ui_Tuple3
45 from Tuple4 import Ui_Tuple4
46 from Tuple5 import Ui_Tuple5
47 from Tuple6 import Ui_Tuple6
48 from Tuple7 import Ui_Tuple7
49 from Tuple8 import Ui_Tuple8
50 from Tuple9 import Ui_Tuple9
51 from Tuple10 import Ui_Tuple10
54 #--------------------------
55 class TupleCustom(object) :
56 #--------------------------
58 def __init__(self,tailleTuple,parent,parentQt,index):
59 #-------------------------------------------------
60 QWidget.__init__(self,parent)
62 self.tailleTuple=tailleTuple
64 self.parentQt=parentQt
67 self.inFocusOutEvent=False
70 for i in range(self.tailleTuple):
71 nomLE="lineEditVal_"+str(i+1)
72 courant=getattr(self,nomLE)
74 courant.dansUnTuple=True
75 courant.returnPressed.connect(self.valueChange)
76 courant.numDsLaListe = i+1
77 courant.tupleCustomParent=self
78 courant.parentTuple = self
81 def valueChange(self):
82 #----------------------
85 for i in range(self.tailleTuple):
86 nomLE="lineEditVal_"+str(i+1)
87 courant=getattr(self,nomLE)
88 val=str(courant.text())
90 if str(val)=="" or val==None :
91 if not self.inFocusOutEvent : courant.setFocus()
98 d=self.parentQt.objSimp.jdc.getContexteAvant(self.parentQt.objSimp. etape)
102 listeVal.append(valeur)
104 self.parentQt.changeValeur()
107 def setValeur(self,value):
108 #----------------------
112 for i in range(self.tailleTuple):
113 nomLE="lineEditVal_"+str(i+1)
114 courant=getattr(self,nomLE)
116 if str(value[i]) != "" : valeurNulle=False
121 courant.setText(str(value[i]))
124 val=str(courant.text())
129 d=self.parentQt.objSimp.jdc.getContexteAvant(self.parentQt.objSimp. etape)
133 listeVal.append(valeur)
134 if valeurNulle == True : self.valeur=None
135 else : self.valeur=listeVal
138 #----------------------
141 for i in range(self.tailleTuple):
142 nomLE="lineEditVal_"+str(i+1)
143 courant=getattr(self,nomLE)
144 self.valeur.append(courant.valeur)
145 if courant.valeur!= None : vide = False
146 if vide : self.valeur=[]
153 def setText(self,value):
154 #-----------------------
155 self.setValeur(value)
160 for i in range(self.tailleTuple):
161 nomLE="lineEditVal_"+str(i+1)
162 courant=getattr(self,nomLE)
165 def finCommentaire(self):
167 return self.finCommentaireListe()
170 #-------------------------------------------------
171 class TupleCustom2(QWidget,Ui_Tuple2,TupleCustom):
172 #-------------------------------------------------
173 def __init__(self,tailleTuple,parent,parentQt,index):
175 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
176 if self.parentQt.editor.maConfiguration.closeParenthese :
181 #-------------------------------------------------
182 class TupleCustom3(QWidget,Ui_Tuple3,TupleCustom):
183 #-------------------------------------------------
184 def __init__(self,tailleTuple,parent,parentQt,index):
186 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
188 #-------------------------------------------------
189 class TupleCustom4(QWidget,Ui_Tuple4,TupleCustom):
190 #-------------------------------------------------
191 def __init__(self,tailleTuple,parent,parentQt,index):
193 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
195 #-------------------------------------------------
196 class TupleCustom5(QWidget,Ui_Tuple5,TupleCustom):
197 #-------------------------------------------------
198 def __init__(self,tailleTuple,parent,parentQt,index):
200 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
202 #-------------------------------------------------
203 class TupleCustom6(QWidget,Ui_Tuple6,TupleCustom):
204 #-------------------------------------------------
205 def __init__(self,tailleTuple,parent,parentQt,index):
207 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
209 #-------------------------------------------------
210 class TupleCustom7(QWidget,Ui_Tuple7,TupleCustom):
211 #-------------------------------------------------
212 def __init__(self,tailleTuple,parent,parentQt,index):
214 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
216 #-------------------------------------------------
217 class TupleCustom8(QWidget,Ui_Tuple8,TupleCustom):
218 #-------------------------------------------------
219 def __init__(self,tailleTuple,parent,parentQt,index):
221 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
223 #-------------------------------------------------
224 class TupleCustom9(QWidget,Ui_Tuple9,TupleCustom):
225 #-------------------------------------------------
226 def __init__(self,tailleTuple,parent,parentQt,index):
228 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
230 #-------------------------------------------------
231 class TupleCustom10(QWidget,Ui_Tuple10,TupleCustom):
232 #-------------------------------------------------
233 def __init__(self,tailleTuple,parent,parentQt,index):
235 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
236 if self.parentQt.editor.maConfiguration.closeParenthese :
244 # -------------------------------------------- #
245 class MonWidgetPlusieursTuple(Feuille,GereListe):
246 # -------------------------------------------- #
248 def __init__(self, node, monSimpDef, nom, objSimp, parentQt, commande):
249 #-----------------------------------------------------
251 self.indexDernierLabel=0
252 self.numLineEditEnCours=0
253 self.nomLine="TupleVal"
254 self.listeAffichageWidget=[]
255 Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
256 GereListe.__init__(self)
257 self.finCommentaireListe()
258 self.politique=PolitiquePlusieurs(self.node,self.editor)
259 self.parentQt.commandesLayout.insertWidget(-1,self)
261 if sys.platform[0:5]!="linux":
262 repIcon=self.node.editor.appliEficas.repIcon
263 fichier=os.path.join(repIcon, 'arrow_up.png')
264 icon = QIcon(fichier)
265 self.RBHaut.setIcon(icon)
266 self.RBHaut.setIconSize(QSize(32, 32))
267 fichier2=os.path.join(repIcon, 'arrow_down.png')
268 icon2 = QIcon(fichier2)
269 self.RBBas.setIcon(icon2)
270 fichier3=os.path.join(repIcon, 'file-explorer.png')
271 icon3 = QIcon(fichier3)
272 self.BSelectFichier.setIcon(icon3)
273 self.BSelectFichier.setIconSize(QSize(32, 32))
274 self.BSelectFichier.clicked.connect(self.selectInFile)
279 def ajoutLineEdit(self,valeur=None,inInit=False):
280 #------------------------------------------------
281 self.indexDernierLabel=self.indexDernierLabel+1
282 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
283 if hasattr(self,nomLineEdit) :
284 self.indexDernierLabel=self.indexDernierLabel-1
287 nomCustomTuple='TupleCustom'+str(self.nbValeurs)
288 laClasseDuTuple=globals()[nomCustomTuple]
289 nouveauLE=laClasseDuTuple(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
291 #if self.nbValeurs == 2 : nouveauLE = TupleCustom2(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
292 #else : nouveauLE = TupleCustom3(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
294 self.verticalLayoutLE.insertWidget(self.indexDernierLabel-1,nouveauLE)
295 setattr(self,nomLineEdit,nouveauLE)
296 if valeur != None : nouveauLE.setValeur(valeur)
298 for i in range(self.nbValeurs) :
300 nomLineEdit='lineEditVal_'+str(num)
301 lineEditVal=getattr(nouveauLE,nomLineEdit)
302 self.listeAffichageWidget.append(lineEditVal)
303 #self.listeAffichageWidget.append(nouveauLE.lineEditVal_1)
304 #self.listeAffichageWidget.append(nouveauLE.lineEditVal_2)
305 #if self.nbValeurs == 3 : self.listeAffichageWidget.append(nouveauLE.lineEditVal_3)
309 # deux lignes pour que le ensureVisible fonctionne
310 self.estVisible=nouveauLE.lineEditVal_1
311 if inInit==False :QTimer.singleShot(1, self.rendVisibleLigne)
313 def etablitOrdre(self):
314 # ---------------------
316 while(i +1 < len(self.listeAffichageWidget)):
317 self.listeAffichageWidget[i].setFocusPolicy(Qt.StrongFocus)
318 self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
322 def setValeurs(self):
323 # ---------------------
324 if self.editor.code == 'PSEN' : self.RBListePush()
325 valeurs=self.node.item.getValeur()
326 min,max=self.node.item.getMinMax()
327 if max == "**" or max > 8 : aCreer= 8
330 if valeurs == () or valeurs == None :
331 for i in range(aCreer): self.ajoutLineEdit(inInit=True)
335 self.ajoutLineEdit(v,inInit=True)
337 for i in range(len(valeurs),aCreer) : self.ajoutLineEdit(inInit=True)
339 def rendVisibleLigne(self):
340 # -------------------------
341 QApplication.processEvents()
342 self.estVisible.setFocus(True)
343 self.scrollArea.ensureWidgetVisible(self.estVisible,0,0)
346 def changeValeur(self,changeDePlace=False,oblige=True):
347 # -----------------------------------------------------
348 #Pour compatibilite signature
350 aLeFocus=self.focusWidget()
353 #print (self.indexDernierLabel)
354 for i in range(self.indexDernierLabel) :
355 nom=self.nomLine+str(i+1)
356 courant=getattr(self,nom)
357 valeurTuple=courant.valeur
358 #print (courant, i, valeurTuple)
359 if valeurTuple == None or valeurTuple== "" or valeurTuple==[]:
362 validite,comm,comm2,listeRetour= self.politique.ajoutTuple(valeurTuple,listeComplete)
364 if comm2 != '' : comm += " " + comm2
365 self.editor.afficheInfos(comm+" "+str(self.objSimp.definition.validators.typeDesTuples),Qt.red)
367 listeComplete.append(tuple(courant.valeur))
368 #print ('listeComplete', listeComplete)
369 if listeComplete == [] : listeComplete=None
370 self.node.item.setValeur(listeComplete)
372 if changeDePlace : return
373 min,max=self.node.item.getMinMax()
374 if self.indexDernierLabel == max : self.editor.afficheInfos(tr('Nb maximum de valeurs atteint'))
375 if self.indexDernierLabel < max and libre==False :
377 self.listeAffichageWidget[-2].setFocus(True)
380 QApplication.processEvents()
381 w=self.listeAffichageWidget[self.listeAffichageWidget.index(aLeFocus)+1]
383 self.scrollArea.ensureWidgetVisible(w,0,0)
387 def ajoutNValeur(self,liste):
388 #----------------------------
389 # attention quand on charge par un fichier, on ne peut pas se contenter d ajouter N fois 1 valeur
390 # car alors le temps de verification devient prohibitif reconstructu=ion et verification a
391 # chaque valeur. d ou l ajout de ajoutNTuple a politique plusieurs
393 if len(liste)%self.nbValeurs != 0 :
394 texte="Nombre incorrect de valeurs"
395 self.editor.afficheInfos(tr(texte),Qt.red)
399 longueur=len(liste)//self.nbValeurs
400 increment=self.nbValeurs
401 listeFormatee=[liste[k*increment:(k+1)*increment] for k in range(longueur)]
402 listeFormatee=tuple(listeFormatee)
404 min,max=self.node.item.getMinMax()
405 if self.objSimp.valeur == None : listeComplete=listeFormatee
406 else : listeComplete =self.objSimp.valeur + listeFormatee
408 if len(listeComplete) > max :
409 texte=tr("Nombre maximum de valeurs ")+str(max)+tr(" atteint")
410 self.editor.afficheInfos(texte,Qt.red)
413 validite,comm,comm2,listeRetour= self.politique.ajoutNTuple(listeComplete)
415 self.editor.afficheInfos(comm+comm2,Qt.red)
418 # on calcule le dernier lineedit rempli avant de changer la valeur
419 if self.objSimp.valeur != None : indexDernierRempli=len(self.objSimp.valeur)
420 else : indexDernierRempli=0
422 self.politique.recordValeur(listeComplete)
424 while ( i < len(liste) ) :
426 t=tuple(liste[i:i+self.nbValeurs])
428 t=tuple(liste[i:len(liste)])
430 if indexDernierRempli < self.indexDernierLabel:
432 nomLEARemplir=self.nomLine+str(indexDernierRempli+1)
433 LEARemplir=getattr(self,nomLEARemplir)
434 for n in range(self.nbValeurs) :
435 nomLineEdit='lineEditVal_'+str(n+1)
436 lineEditVal=getattr(LEARemplir,nomLineEdit)
437 lineEditVal.setText(str(t[n]))
439 # ne pas appeler ajoutLineEdit(t,False ) pb de boucle pb du a etablitOrdre et a listeWidgetAffichage qui bouge
440 self.indexDernierLabel=self.indexDernierLabel+1
441 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
443 nomCustomTuple='TupleCustom'+str(self.nbValeurs)
444 laClasseDuTuple=globals()[nomCustomTuple]
445 nouveauLE=laClasseDuTuple(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
447 self.verticalLayoutLE.insertWidget(self.indexDernierLabel-1,nouveauLE)
448 setattr(self,nomLineEdit,nouveauLE)
449 nouveauLE.setValeur(t)
451 for n in range(self.nbValeurs) :
452 nomLineEdit='lineEditVal_'+str(n+1)
453 lineEditVal=getattr(nouveauLE,nomLineEdit)
454 self.listeAffichageWidget.append(lineEditVal)
455 indexDernierRempli = indexDernierRempli+1
461 def RBListePush(self):
462 #----------------------
463 # PN a rendre generique avec un truc tel prerempli
464 # pour l instant specifique PSEN
466 if self.editor.code == 'VP' : return
467 if self.objSimp.valeur != None and self.objSimp.valeur != [] : return
468 if not hasattr(self.editor.readercata.cata,'sd_ligne') : self.editor.readercata.cata.sd_ligne=None
469 if not hasattr(self.editor.readercata.cata,'sd_generateur') : self.editor.readercata.cata.sd_generateur=None
470 if not hasattr(self.editor.readercata.cata,'sd_transfo') : self.editor.readercata.cata.sd_transfo=None
471 if not hasattr(self.editor.readercata.cata,'sd_charge') : self.editor.readercata.cata.sd_charge=None
472 if not hasattr(self.editor.readercata.cata,'sd_moteur') : self.editor.readercata.cata.sd_moteur=None
473 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_ligne :
475 if hasattr(self.objSimp.jdc,'LineDico'):
476 for k in self.objSimp.jdc.LineDico :
478 valeur=self.objSimp.jdc.getConcept(k)
479 val.append((valeur,0))
482 self.node.item.setValeur(val)
483 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_generateur :
485 if hasattr(self.objSimp.jdc,'MachineDico'):
486 for k in self.objSimp.jdc.MachineDico :
488 valeur=self.objSimp.jdc.getConcept(k)
489 val.append((valeur,0))
492 self.node.item.setValeur(val)
493 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_transfo :
495 if hasattr(self.objSimp.jdc,'TransfoDico'):
496 for k in self.objSimp.jdc.TransfoDico :
498 valeur=self.objSimp.jdc.getConcept(k)
499 val.append((valeur,0))
502 self.node.item.setValeur(val)
503 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_charge :
505 if hasattr(self.objSimp.jdc,'LoadDico'):
506 for k in self.objSimp.jdc.LoadDico :
508 valeur=self.objSimp.jdc.getConcept(k)
509 val.append((valeur,0))
512 self.node.item.setValeur(val)
513 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_moteur :
515 if hasattr(self.objSimp.jdc,'MotorDico'):
516 for k in self.objSimp.jdc.MotorDico :
518 valeur=self.objSimp.jdc.getConcept(k)
519 val.append((valeur,0))
522 self.node.item.setValeur(val)