]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/monWidgetPlusieursTuple.py
Salome HOME
bug sur un mesage dans une exception sur un validator (cf JPA)
[tools/eficas.git] / InterfaceQT4 / monWidgetPlusieursTuple.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Modules Python
21 from __future__ import absolute_import
22 try :
23     from builtins import str
24     from builtins import range
25     from builtins import object
26 except : pass
27
28 import types,os,sys
29
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
34
35 from Extensions.i18n import tr
36
37
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
52
53
54 #--------------------------
55 class TupleCustom(object) :
56 #--------------------------
57
58     def __init__(self,tailleTuple,parent,parentQt,index):
59     #-------------------------------------------------
60         QWidget.__init__(self,parent)
61         self.setupUi(self)
62         self.tailleTuple=tailleTuple
63         self.parent=parent
64         self.parentQt=parentQt
65         self.valeur=[]
66         self.index=index
67         self.inFocusOutEvent=False
68
69
70         for i in range(self.tailleTuple):
71             nomLE="lineEditVal"+str(i+1)
72             courant=getattr(self,nomLE)
73             courant.num=index
74             courant.dansUnTuple=True
75             courant.returnPressed.connect(self.valueChange)
76             courant.numDsLaListe = i+1
77             courant.tupleCustomParent=self
78             courant.parentTuple = self
79
80
81     def valueChange(self):
82     #----------------------
83
84         listeVal=[]
85         for i in range(self.tailleTuple):
86             nomLE="lineEditVal"+str(i+1)
87             courant=getattr(self,nomLE)
88             val=str(courant.text())
89
90             if str(val)=="" or val==None :
91                 if not self.inFocusOutEvent : courant.setFocus()
92                 return
93
94             try :
95                 valeur=eval(val,{})
96             except :
97                 try :
98                     d=self.parentQt.objSimp.jdc.getContexteAvant(self.parentQt.objSimp. etape)
99                     valeur=eval(val,d)
100                 except :
101                     valeur=val
102             listeVal.append(valeur)
103         self.valeur=listeVal
104         self.parentQt.changeValeur()
105
106
107     def setValeur(self,value):
108     #----------------------
109
110         listeVal=[]
111         valeurNulle=True
112         for i in range(self.tailleTuple):
113             nomLE="lineEditVal"+str(i+1)
114             courant=getattr(self,nomLE)
115             try :
116                 if str(value[i]) != "" : valeurNulle=False
117             except :
118                 pass
119
120             try :
121                 courant.setText(str(value[i]))
122             except :
123                 courant.setText("")
124             val=str(courant.text())
125             try :
126                 valeur=eval(val,{})
127             except :
128                 try :
129                     d=self.parentQt.objSimp.jdc.getContexteAvant(self.parentQt.objSimp. etape)
130                     valeur=eval(val,d)
131                 except :
132                     valeur=val
133             listeVal.append(valeur)
134         if  valeurNulle == True : self.valeur=None
135         else                    : self.valeur=listeVal
136
137     def getValeurbad(self):
138     #----------------------
139         self.valeur=[]
140         vide=True
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=[]
148         return self.valeur
149
150     def getValeur(self):
151     #----------------------
152         return self.valeur
153
154
155     def text(self):
156     #--------------
157         return self.valeur
158
159     def setText(self,value):
160     #-----------------------
161         self.setValeur(value)
162
163     def clean(self):
164     #-------------------
165         self.valeur=None
166         for i in range(self.tailleTuple):
167             nomLE="lineEditVal"+str(i+1)
168             courant=getattr(self,nomLE)
169             courant.setText("")
170
171     def finCommentaire(self):
172     #-------------------
173         return self.finCommentaireListe()
174
175
176 #-------------------------------------------------
177 class TupleCustom2(QWidget,Ui_Tuple2,TupleCustom):
178 #-------------------------------------------------
179     def __init__(self,tailleTuple,parent,parentQt,index):
180     #-------------------
181         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
182         if self.parentQt.editor.maConfiguration.closeParenthese :
183             self.label_5.close()
184             self.label_7.close()
185
186
187 #-------------------------------------------------
188 class TupleCustom3(QWidget,Ui_Tuple3,TupleCustom):
189 #-------------------------------------------------
190     def __init__(self,tailleTuple,parent,parentQt,index):
191     #-------------------
192         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
193
194 #-------------------------------------------------
195 class TupleCustom4(QWidget,Ui_Tuple4,TupleCustom):
196 #-------------------------------------------------
197     def __init__(self,tailleTuple,parent,parentQt,index):
198     #-------------------
199         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
200
201 #-------------------------------------------------
202 class TupleCustom5(QWidget,Ui_Tuple5,TupleCustom):
203 #-------------------------------------------------
204     def __init__(self,tailleTuple,parent,parentQt,index):
205     #-------------------
206         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
207
208 #-------------------------------------------------
209 class TupleCustom6(QWidget,Ui_Tuple6,TupleCustom):
210 #-------------------------------------------------
211     def __init__(self,tailleTuple,parent,parentQt,index):
212     #-------------------
213         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
214
215 #-------------------------------------------------
216 class TupleCustom7(QWidget,Ui_Tuple7,TupleCustom):
217 #-------------------------------------------------
218     def __init__(self,tailleTuple,parent,parentQt,index):
219     #-------------------
220         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
221
222 #-------------------------------------------------
223 class TupleCustom8(QWidget,Ui_Tuple8,TupleCustom):
224 #-------------------------------------------------
225     def __init__(self,tailleTuple,parent,parentQt,index):
226     #-------------------
227         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
228
229 #-------------------------------------------------
230 class TupleCustom9(QWidget,Ui_Tuple9,TupleCustom):
231 #-------------------------------------------------
232     def __init__(self,tailleTuple,parent,parentQt,index):
233     #-------------------
234         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
235
236 #-------------------------------------------------
237 class TupleCustom10(QWidget,Ui_Tuple10,TupleCustom):
238 #-------------------------------------------------
239     def __init__(self,tailleTuple,parent,parentQt,index):
240     #-------------------
241         TupleCustom.__init__(self,tailleTuple,parent,parentQt,index)
242         if self.parentQt.editor.maConfiguration.closeParenthese :
243             self.label_5.close()
244             self.label_7.close()
245
246
247
248
249
250 # -------------------------------------------- #
251 class MonWidgetPlusieursTuple(Feuille,GereListe):
252 # -------------------------------------------- #
253
254     def __init__(self, node, monSimpDef, nom, objSimp, parentQt, commande):
255     #-----------------------------------------------------
256
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)
266
267         #if sys.platform[0:5]!="linux":
268         if 1 :
269         #Pour MT
270             repIcon=self.node.editor.appliEficas.repIcon
271             fichier=os.path.join(repIcon, 'arrow_up.png')
272             icon = QIcon(fichier)
273             self.RBHaut.setIcon(icon)
274             self.RBHaut.setIconSize(QSize(32, 32))
275             fichier2=os.path.join(repIcon, 'arrow_down.png')
276             icon2 = QIcon(fichier2)
277             self.RBBas.setIcon(icon2)
278             fichier3=os.path.join(repIcon, 'file-explorer.png')
279             icon3 = QIcon(fichier3)
280             self.BSelectFichier.setIcon(icon3)
281             self.BSelectFichier.setIconSize(QSize(32, 32))
282         self.BSelectFichier.clicked.connect(self.selectInFile)
283
284
285
286
287     def ajoutLineEdit(self,valeur=None,inInit=False):
288     #------------------------------------------------
289         self.indexDernierLabel=self.indexDernierLabel+1
290         nomLineEdit=self.nomLine+str(self.indexDernierLabel)
291         if hasattr(self,nomLineEdit) :
292             self.indexDernierLabel=self.indexDernierLabel-1
293             return
294
295         nomCustomTuple='TupleCustom'+str(self.nbValeurs)
296         laClasseDuTuple=globals()[nomCustomTuple]
297         nouveauLE=laClasseDuTuple(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
298
299         #if self.nbValeurs == 2 : nouveauLE = TupleCustom2(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
300         #else                   : nouveauLE = TupleCustom3(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
301
302         self.verticalLayoutLE.insertWidget(self.indexDernierLabel-1,nouveauLE)
303         setattr(self,nomLineEdit,nouveauLE)
304         if valeur != None : nouveauLE.setValeur(valeur)
305
306         for i in range(self.nbValeurs) :
307             num=i+1
308             nomLineEdit='lineEditVal'+str(num)
309             lineEditVal=getattr(nouveauLE,nomLineEdit)
310             self.listeAffichageWidget.append(lineEditVal)
311         #self.listeAffichageWidget.append(nouveauLE.lineEditVal1)
312         #self.listeAffichageWidget.append(nouveauLE.lineEditVal2)
313         #if self.nbValeurs == 3 : self.listeAffichageWidget.append(nouveauLE.lineEditVal3)
314
315         self.etablitOrdre()
316
317         # deux lignes pour que le ensureVisible fonctionne
318         self.estVisible=nouveauLE.lineEditVal1
319         if inInit==False :QTimer.singleShot(1, self.rendVisibleLigne)
320
321     def etablitOrdre(self):
322     # ---------------------
323         i=0
324         while(i +1 < len(self.listeAffichageWidget)):
325             self.listeAffichageWidget[i].setFocusPolicy(Qt.StrongFocus)
326             self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
327             i=i+1
328
329
330     def setValeurs(self):
331     # ---------------------
332         if self.editor.code == 'PSEN' : self.RBListePush()
333         valeurs=self.node.item.getValeur()
334         min,max=self.node.item.getMinMax()
335         if max == "**" or max > 8 : aCreer= 8
336         else : aCreer=max
337
338         if valeurs == () or valeurs == None :
339             for i in range(aCreer): self.ajoutLineEdit(inInit=True)
340             return
341
342         for v in valeurs:
343             self.ajoutLineEdit(v,inInit=True)
344
345         for i in range(len(valeurs),aCreer) : self.ajoutLineEdit(inInit=True)
346
347     def rendVisibleLigne(self):
348     # -------------------------
349         QApplication.processEvents()
350         self.estVisible.setFocus(True)
351         self.scrollArea.ensureWidgetVisible(self.estVisible,0,0)
352
353
354     def changeValeur(self,changeDePlace=False,oblige=True):
355     # -----------------------------------------------------
356         #Pour compatibilite signature
357         #print ('dschangeValeur', self.indexDernierLabel)
358
359         aLeFocus=self.focusWidget()
360         listeComplete=[]
361         libre=False
362         #print (self.indexDernierLabel)
363         for i in range(self.indexDernierLabel) :
364             nom=self.nomLine+str(i+1)
365             courant=getattr(self,nom)
366             valeurTuple=courant.valeur
367             if valeurTuple == None or valeurTuple== "" or valeurTuple==[]:
368                 libre=True
369                 continue
370             validite,comm,comm2,listeRetour= self.politique.ajoutTuple(valeurTuple,listeComplete)
371             if not validite:
372                 if comm2 != '' : comm += " " + comm2
373                 self.editor.afficheInfos(comm+" "+str(self.objSimp.definition.validators.typeDesTuples),Qt.red)
374                 return
375             listeComplete.append(tuple(courant.valeur))
376         #print ('listeComplete', listeComplete)
377         if listeComplete == [] : listeComplete=None
378         self.node.item.setValeur(listeComplete)
379
380         if changeDePlace : return
381         min,max=self.node.item.getMinMax()
382         if self.indexDernierLabel == max  : self.editor.afficheInfos(tr('Nb maximum de valeurs atteint'))
383         if self.indexDernierLabel < max and libre==False :
384             self.ajoutLineEdit()
385             self.listeAffichageWidget[-2].setFocus(True)
386         else :
387             try :
388                 QApplication.processEvents()
389                 w=self.listeAffichageWidget[self.listeAffichageWidget.index(aLeFocus)+1]
390                 w.setFocus(True)
391                 self.scrollArea.ensureWidgetVisible(w,0,0)
392             except :
393                 pass
394
395     def echange(self,num1,num2):
396         # on donne le focus au a celui ou on a bouge
397         # par convention le 2
398         nomLineEdit=self.nomLine+str(num1)
399         courant=getattr(self,nomLineEdit)
400         valeurAGarder=courant.getValeur()
401         nomLineEdit2=self.nomLine+str(num2)
402         courant2=getattr(self,nomLineEdit2)
403         courant.setText(courant2.text())
404         courant2.setText(valeurAGarder)
405         self.changeValeur(changeDePlace=True)
406         self.numLineEditEnCours=num2
407         self.lineEditEnCours=courant2
408         courant2.lineEditVal1.setFocus(True)
409
410     def ajoutNValeur(self,liste):
411     #----------------------------
412     # attention quand on charge par un fichier, on ne peut pas se contenter d ajouter N fois 1 valeur
413     # car alors le temps de verification devient prohibitif  reconstructu=ion et verification a
414     # chaque valeur. d ou l ajout de ajoutNTuple a politique plusieurs
415
416         if len(liste)%self.nbValeurs != 0 :
417             texte="Nombre incorrect de valeurs"
418             self.editor.afficheInfos(tr(texte),Qt.red)
419             return
420
421         i=0
422         longueur=len(liste)//self.nbValeurs
423         increment=self.nbValeurs
424         listeFormatee=[liste[k*increment:(k+1)*increment] for k in range(longueur)]
425         listeFormatee=tuple(listeFormatee)
426
427         min,max=self.node.item.getMinMax()
428         if self.objSimp.valeur == None : listeComplete=listeFormatee
429         else : listeComplete =self.objSimp.valeur + listeFormatee
430
431         if len(listeComplete) > max :
432             texte=tr("Nombre maximum de valeurs ")+str(max)+tr(" atteint")
433             self.editor.afficheInfos(texte,Qt.red)
434             return
435
436         validite,comm,comm2,listeRetour= self.politique.ajoutNTuple(listeComplete)
437         if not validite :
438             self.editor.afficheInfos(comm+comm2,Qt.red)
439             return
440
441         # on calcule le dernier lineedit rempli avant de changer la valeur
442         if self.objSimp.valeur != None : indexDernierRempli=len(self.objSimp.valeur)
443         else : indexDernierRempli=0
444
445         self.politique.recordValeur(listeComplete)
446
447         while ( i < len(liste) ) :
448             try :
449                 t=tuple(liste[i:i+self.nbValeurs])
450             except:
451                 t=tuple(liste[i:len(liste)])
452             i=i+self.nbValeurs
453             if indexDernierRempli < self.indexDernierLabel:
454
455                 nomLEARemplir=self.nomLine+str(indexDernierRempli+1)
456                 LEARemplir=getattr(self,nomLEARemplir)
457                 for n in range(self.nbValeurs) :
458                     nomLineEdit='lineEditVal'+str(n+1)
459                     lineEditVal=getattr(LEARemplir,nomLineEdit)
460                     lineEditVal.setText(str(t[n]))
461             else :
462                 # ne pas appeler ajoutLineEdit(t,False ) pb de boucle pb du a etablitOrdre et a listeWidgetAffichage qui bouge
463                 self.indexDernierLabel=self.indexDernierLabel+1
464                 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
465
466                 nomCustomTuple='TupleCustom'+str(self.nbValeurs)
467                 laClasseDuTuple=globals()[nomCustomTuple]
468                 nouveauLE=laClasseDuTuple(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
469
470                 self.verticalLayoutLE.insertWidget(self.indexDernierLabel-1,nouveauLE)
471                 setattr(self,nomLineEdit,nouveauLE)
472                 nouveauLE.setValeur(t)
473
474                 for n in range(self.nbValeurs) :
475                     nomLineEdit='lineEditVal'+str(n+1)
476                     lineEditVal=getattr(nouveauLE,nomLineEdit)
477                     self.listeAffichageWidget.append(lineEditVal)
478             indexDernierRempli = indexDernierRempli+1
479
480         self.etablitOrdre()
481
482
483
484     def RBListePush(self):
485     #----------------------
486     # PN a rendre generique avec un truc tel prerempli
487     # pour l instant specifique PSEN
488
489         if self.editor.code == 'VP' : return
490         if self.objSimp.valeur != None and self.objSimp.valeur != [] : return
491         if not hasattr(self.editor.readercata.cata,'sd_ligne') : self.editor.readercata.cata.sd_ligne=None
492         if not hasattr(self.editor.readercata.cata,'sd_generateur') : self.editor.readercata.cata.sd_generateur=None
493         if not hasattr(self.editor.readercata.cata,'sd_transfo') : self.editor.readercata.cata.sd_transfo=None
494         if not hasattr(self.editor.readercata.cata,'sd_charge') : self.editor.readercata.cata.sd_charge=None
495         if not hasattr(self.editor.readercata.cata,'sd_moteur') : self.editor.readercata.cata.sd_moteur=None
496         if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_ligne :
497             val=[]
498             if  hasattr(self.objSimp.jdc,'LineDico'):
499                 for k in self.objSimp.jdc.LineDico :
500                     try :
501                         valeur=self.objSimp.jdc.getConcept(k)
502                         val.append((valeur,0))
503                     except :
504                         pass
505             self.node.item.setValeur(val)
506         if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_generateur :
507             val=[]
508             if  hasattr(self.objSimp.jdc,'MachineDico'):
509                 for k in self.objSimp.jdc.MachineDico :
510                     try :
511                         valeur=self.objSimp.jdc.getConcept(k)
512                         val.append((valeur,0))
513                     except :
514                         pass
515             self.node.item.setValeur(val)
516         if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_transfo :
517             val=[]
518             if  hasattr(self.objSimp.jdc,'TransfoDico'):
519                 for k in self.objSimp.jdc.TransfoDico :
520                     try :
521                         valeur=self.objSimp.jdc.getConcept(k)
522                         val.append((valeur,0))
523                     except :
524                         pass
525             self.node.item.setValeur(val)
526         if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_charge :
527             val=[]
528             if  hasattr(self.objSimp.jdc,'LoadDico'):
529                 for k in self.objSimp.jdc.LoadDico :
530                     try :
531                         valeur=self.objSimp.jdc.getConcept(k)
532                         val.append((valeur,0))
533                     except :
534                         pass
535             self.node.item.setValeur(val)
536         if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_moteur :
537             val=[]
538             if  hasattr(self.objSimp.jdc,'MotorDico'):
539                 for k in self.objSimp.jdc.MotorDico :
540                     try :
541                         valeur=self.objSimp.jdc.getConcept(k)
542                         val.append((valeur,0))
543                     except :
544                         pass
545             self.node.item.setValeur(val)