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
137 def getValeurbad(self):
138 #----------------------
141 print (self.tailleTuple)
142 for i in range(self.tailleTuple):
143 nomLE="lineEditVal_"+str(i+1)
144 courant=getattr(self,nomLE)
145 self.valeur.append(courant.valeur)
146 if courant.valeur!= None : vide = False
147 if vide : self.valeur=[]
151 #----------------------
159 def setText(self,value):
160 #-----------------------
161 self.setValeur(value)
166 for i in range(self.tailleTuple):
167 nomLE="lineEditVal_"+str(i+1)
168 courant=getattr(self,nomLE)
171 def finCommentaire(self):
173 return self.finCommentaireListe()
176 #-------------------------------------------------
177 class TupleCustom2(QWidget,Ui_Tuple2,TupleCustom):
178 #-------------------------------------------------
179 def __init__(self,tailleTuple,parent,parentQt,index):
181 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
182 if self.parentQt.editor.maConfiguration.closeParenthese :
187 #-------------------------------------------------
188 class TupleCustom3(QWidget,Ui_Tuple3,TupleCustom):
189 #-------------------------------------------------
190 def __init__(self,tailleTuple,parent,parentQt,index):
192 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
194 #-------------------------------------------------
195 class TupleCustom4(QWidget,Ui_Tuple4,TupleCustom):
196 #-------------------------------------------------
197 def __init__(self,tailleTuple,parent,parentQt,index):
199 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
201 #-------------------------------------------------
202 class TupleCustom5(QWidget,Ui_Tuple5,TupleCustom):
203 #-------------------------------------------------
204 def __init__(self,tailleTuple,parent,parentQt,index):
206 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
208 #-------------------------------------------------
209 class TupleCustom6(QWidget,Ui_Tuple6,TupleCustom):
210 #-------------------------------------------------
211 def __init__(self,tailleTuple,parent,parentQt,index):
213 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
215 #-------------------------------------------------
216 class TupleCustom7(QWidget,Ui_Tuple7,TupleCustom):
217 #-------------------------------------------------
218 def __init__(self,tailleTuple,parent,parentQt,index):
220 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
222 #-------------------------------------------------
223 class TupleCustom8(QWidget,Ui_Tuple8,TupleCustom):
224 #-------------------------------------------------
225 def __init__(self,tailleTuple,parent,parentQt,index):
227 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
229 #-------------------------------------------------
230 class TupleCustom9(QWidget,Ui_Tuple9,TupleCustom):
231 #-------------------------------------------------
232 def __init__(self,tailleTuple,parent,parentQt,index):
234 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
236 #-------------------------------------------------
237 class TupleCustom10(QWidget,Ui_Tuple10,TupleCustom):
238 #-------------------------------------------------
239 def __init__(self,tailleTuple,parent,parentQt,index):
241 TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
242 if self.parentQt.editor.maConfiguration.closeParenthese :
250 # -------------------------------------------- #
251 class MonWidgetPlusieursTuple(Feuille,GereListe):
252 # -------------------------------------------- #
254 def __init__(self, node, monSimpDef, nom, objSimp, parentQt, commande):
255 #-----------------------------------------------------
257 self.indexDernierLabel=0
258 self.numLineEditEnCours=0
259 self.nomLine="TupleVal"
260 self.listeAffichageWidget=[]
261 Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
262 GereListe.__init__(self)
263 self.finCommentaireListe()
264 self.politique=PolitiquePlusieurs(self.node,self.editor)
265 self.parentQt.commandesLayout.insertWidget(-1,self)
267 if sys.platform[0:5]!="linux":
268 repIcon=self.node.editor.appliEficas.repIcon
269 fichier=os.path.join(repIcon, 'arrow_up.png')
270 icon = QIcon(fichier)
271 self.RBHaut.setIcon(icon)
272 self.RBHaut.setIconSize(QSize(32, 32))
273 fichier2=os.path.join(repIcon, 'arrow_down.png')
274 icon2 = QIcon(fichier2)
275 self.RBBas.setIcon(icon2)
276 fichier3=os.path.join(repIcon, 'file-explorer.png')
277 icon3 = QIcon(fichier3)
278 self.BSelectFichier.setIcon(icon3)
279 self.BSelectFichier.setIconSize(QSize(32, 32))
280 self.BSelectFichier.clicked.connect(self.selectInFile)
285 def ajoutLineEdit(self,valeur=None,inInit=False):
286 #------------------------------------------------
287 self.indexDernierLabel=self.indexDernierLabel+1
288 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
289 if hasattr(self,nomLineEdit) :
290 self.indexDernierLabel=self.indexDernierLabel-1
293 nomCustomTuple='TupleCustom'+str(self.nbValeurs)
294 laClasseDuTuple=globals()[nomCustomTuple]
295 nouveauLE=laClasseDuTuple(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
297 #if self.nbValeurs == 2 : nouveauLE = TupleCustom2(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
298 #else : nouveauLE = TupleCustom3(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
300 self.verticalLayoutLE.insertWidget(self.indexDernierLabel-1,nouveauLE)
301 setattr(self,nomLineEdit,nouveauLE)
302 if valeur != None : nouveauLE.setValeur(valeur)
304 for i in range(self.nbValeurs) :
306 nomLineEdit='lineEditVal_'+str(num)
307 lineEditVal=getattr(nouveauLE,nomLineEdit)
308 self.listeAffichageWidget.append(lineEditVal)
309 #self.listeAffichageWidget.append(nouveauLE.lineEditVal_1)
310 #self.listeAffichageWidget.append(nouveauLE.lineEditVal_2)
311 #if self.nbValeurs == 3 : self.listeAffichageWidget.append(nouveauLE.lineEditVal_3)
315 # deux lignes pour que le ensureVisible fonctionne
316 self.estVisible=nouveauLE.lineEditVal_1
317 if inInit==False :QTimer.singleShot(1, self.rendVisibleLigne)
319 def etablitOrdre(self):
320 # ---------------------
322 while(i +1 < len(self.listeAffichageWidget)):
323 self.listeAffichageWidget[i].setFocusPolicy(Qt.StrongFocus)
324 self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
328 def setValeurs(self):
329 # ---------------------
330 if self.editor.code == 'PSEN' : self.RBListePush()
331 valeurs=self.node.item.getValeur()
332 min,max=self.node.item.getMinMax()
333 if max == "**" or max > 8 : aCreer= 8
336 if valeurs == () or valeurs == None :
337 for i in range(aCreer): self.ajoutLineEdit(inInit=True)
341 self.ajoutLineEdit(v,inInit=True)
343 for i in range(len(valeurs),aCreer) : self.ajoutLineEdit(inInit=True)
345 def rendVisibleLigne(self):
346 # -------------------------
347 QApplication.processEvents()
348 self.estVisible.setFocus(True)
349 self.scrollArea.ensureWidgetVisible(self.estVisible,0,0)
352 def changeValeur(self,changeDePlace=False,oblige=True):
353 # -----------------------------------------------------
354 #Pour compatibilite signature
355 #print ('dschangeValeur', self.indexDernierLabel)
357 aLeFocus=self.focusWidget()
360 #print (self.indexDernierLabel)
361 for i in range(self.indexDernierLabel) :
362 nom=self.nomLine+str(i+1)
363 courant=getattr(self,nom)
364 valeurTuple=courant.valeur
365 if valeurTuple == None or valeurTuple== "" or valeurTuple==[]:
368 validite,comm,comm2,listeRetour= self.politique.ajoutTuple(valeurTuple,listeComplete)
370 if comm2 != '' : comm += " " + comm2
371 self.editor.afficheInfos(comm+" "+str(self.objSimp.definition.validators.typeDesTuples),Qt.red)
373 listeComplete.append(tuple(courant.valeur))
374 #print ('listeComplete', listeComplete)
375 if listeComplete == [] : listeComplete=None
376 self.node.item.setValeur(listeComplete)
378 if changeDePlace : return
379 min,max=self.node.item.getMinMax()
380 if self.indexDernierLabel == max : self.editor.afficheInfos(tr('Nb maximum de valeurs atteint'))
381 if self.indexDernierLabel < max and libre==False :
383 self.listeAffichageWidget[-2].setFocus(True)
386 QApplication.processEvents()
387 w=self.listeAffichageWidget[self.listeAffichageWidget.index(aLeFocus)+1]
389 self.scrollArea.ensureWidgetVisible(w,0,0)
393 def echange(self,num1,num2):
394 # on donne le focus au a celui ou on a bouge
395 # par convention le 2
396 nomLineEdit=self.nomLine+str(num1)
397 courant=getattr(self,nomLineEdit)
398 valeurAGarder=courant.getValeur()
399 nomLineEdit2=self.nomLine+str(num2)
400 courant2=getattr(self,nomLineEdit2)
401 courant.setText(courant2.text())
402 courant2.setText(valeurAGarder)
403 self.changeValeur(changeDePlace=True)
404 self.numLineEditEnCours=num2
405 self.LineEditEnCours=courant2
406 courant2.lineEditVal_1.setFocus(True)
408 def ajoutNValeur(self,liste):
409 #----------------------------
410 # attention quand on charge par un fichier, on ne peut pas se contenter d ajouter N fois 1 valeur
411 # car alors le temps de verification devient prohibitif reconstructu=ion et verification a
412 # chaque valeur. d ou l ajout de ajoutNTuple a politique plusieurs
414 if len(liste)%self.nbValeurs != 0 :
415 texte="Nombre incorrect de valeurs"
416 self.editor.afficheInfos(tr(texte),Qt.red)
420 longueur=len(liste)//self.nbValeurs
421 increment=self.nbValeurs
422 listeFormatee=[liste[k*increment:(k+1)*increment] for k in range(longueur)]
423 listeFormatee=tuple(listeFormatee)
425 min,max=self.node.item.getMinMax()
426 if self.objSimp.valeur == None : listeComplete=listeFormatee
427 else : listeComplete =self.objSimp.valeur + listeFormatee
429 if len(listeComplete) > max :
430 texte=tr("Nombre maximum de valeurs ")+str(max)+tr(" atteint")
431 self.editor.afficheInfos(texte,Qt.red)
434 validite,comm,comm2,listeRetour= self.politique.ajoutNTuple(listeComplete)
436 self.editor.afficheInfos(comm+comm2,Qt.red)
439 # on calcule le dernier lineedit rempli avant de changer la valeur
440 if self.objSimp.valeur != None : indexDernierRempli=len(self.objSimp.valeur)
441 else : indexDernierRempli=0
443 self.politique.recordValeur(listeComplete)
445 while ( i < len(liste) ) :
447 t=tuple(liste[i:i+self.nbValeurs])
449 t=tuple(liste[i:len(liste)])
451 if indexDernierRempli < self.indexDernierLabel:
453 nomLEARemplir=self.nomLine+str(indexDernierRempli+1)
454 LEARemplir=getattr(self,nomLEARemplir)
455 for n in range(self.nbValeurs) :
456 nomLineEdit='lineEditVal_'+str(n+1)
457 lineEditVal=getattr(LEARemplir,nomLineEdit)
458 lineEditVal.setText(str(t[n]))
460 # ne pas appeler ajoutLineEdit(t,False ) pb de boucle pb du a etablitOrdre et a listeWidgetAffichage qui bouge
461 self.indexDernierLabel=self.indexDernierLabel+1
462 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
464 nomCustomTuple='TupleCustom'+str(self.nbValeurs)
465 laClasseDuTuple=globals()[nomCustomTuple]
466 nouveauLE=laClasseDuTuple(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
468 self.verticalLayoutLE.insertWidget(self.indexDernierLabel-1,nouveauLE)
469 setattr(self,nomLineEdit,nouveauLE)
470 nouveauLE.setValeur(t)
472 for n in range(self.nbValeurs) :
473 nomLineEdit='lineEditVal_'+str(n+1)
474 lineEditVal=getattr(nouveauLE,nomLineEdit)
475 self.listeAffichageWidget.append(lineEditVal)
476 indexDernierRempli = indexDernierRempli+1
482 def RBListePush(self):
483 #----------------------
484 # PN a rendre generique avec un truc tel prerempli
485 # pour l instant specifique PSEN
487 if self.editor.code == 'VP' : return
488 if self.objSimp.valeur != None and self.objSimp.valeur != [] : return
489 if not hasattr(self.editor.readercata.cata,'sd_ligne') : self.editor.readercata.cata.sd_ligne=None
490 if not hasattr(self.editor.readercata.cata,'sd_generateur') : self.editor.readercata.cata.sd_generateur=None
491 if not hasattr(self.editor.readercata.cata,'sd_transfo') : self.editor.readercata.cata.sd_transfo=None
492 if not hasattr(self.editor.readercata.cata,'sd_charge') : self.editor.readercata.cata.sd_charge=None
493 if not hasattr(self.editor.readercata.cata,'sd_moteur') : self.editor.readercata.cata.sd_moteur=None
494 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_ligne :
496 if hasattr(self.objSimp.jdc,'LineDico'):
497 for k in self.objSimp.jdc.LineDico :
499 valeur=self.objSimp.jdc.getConcept(k)
500 val.append((valeur,0))
503 self.node.item.setValeur(val)
504 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_generateur :
506 if hasattr(self.objSimp.jdc,'MachineDico'):
507 for k in self.objSimp.jdc.MachineDico :
509 valeur=self.objSimp.jdc.getConcept(k)
510 val.append((valeur,0))
513 self.node.item.setValeur(val)
514 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_transfo :
516 if hasattr(self.objSimp.jdc,'TransfoDico'):
517 for k in self.objSimp.jdc.TransfoDico :
519 valeur=self.objSimp.jdc.getConcept(k)
520 val.append((valeur,0))
523 self.node.item.setValeur(val)
524 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_charge :
526 if hasattr(self.objSimp.jdc,'LoadDico'):
527 for k in self.objSimp.jdc.LoadDico :
529 valeur=self.objSimp.jdc.getConcept(k)
530 val.append((valeur,0))
533 self.node.item.setValeur(val)
534 if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_moteur :
536 if hasattr(self.objSimp.jdc,'MotorDico'):
537 for k in self.objSimp.jdc.MotorDico :
539 valeur=self.objSimp.jdc.getConcept(k)
540 val.append((valeur,0))
543 self.node.item.setValeur(val)