]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/monWidgetPlusieursTuple.py
Salome HOME
correction du big sur le plus
[tools/eficas.git] / InterfaceQT4 / monWidgetPlusieursTuple.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017   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           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)
281  
282
283
284
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
291          return
292
293       nomCustomTuple='TupleCustom'+str(self.nbValeurs)
294       laClasseDuTuple=globals()[nomCustomTuple]
295       nouveauLE=laClasseDuTuple(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
296
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)
299                  
300       self.verticalLayoutLE.insertWidget(self.indexDernierLabel-1,nouveauLE)
301       setattr(self,nomLineEdit,nouveauLE)
302       if valeur != None : nouveauLE.setValeur(valeur)
303
304       for i in range(self.nbValeurs) :
305           num=i+1
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)
312
313       self.etablitOrdre()
314
315       # deux lignes pour que le ensureVisible fonctionne
316       self.estVisible=nouveauLE.lineEditVal_1
317       if inInit==False :QTimer.singleShot(1, self.rendVisibleLigne)
318
319   def etablitOrdre(self):
320   # ---------------------
321       i=0
322       while(i +1 < len(self.listeAffichageWidget)):
323          self.listeAffichageWidget[i].setFocusPolicy(Qt.StrongFocus)
324          self.setTabOrder(self.listeAffichageWidget[i],self.listeAffichageWidget[i+1])
325          i=i+1
326
327
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
334        else : aCreer=max 
335
336        if valeurs == () or valeurs == None :
337           for i in range(aCreer): self.ajoutLineEdit(inInit=True)
338           return
339
340        for v in valeurs:
341            self.ajoutLineEdit(v,inInit=True)
342
343        for i in range(len(valeurs),aCreer) : self.ajoutLineEdit(inInit=True)
344
345   def rendVisibleLigne(self):
346   # -------------------------
347       QApplication.processEvents()
348       self.estVisible.setFocus(True)
349       self.scrollArea.ensureWidgetVisible(self.estVisible,0,0)
350
351    
352   def changeValeur(self,changeDePlace=False,oblige=True):
353   # -----------------------------------------------------
354       #Pour compatibilite signature
355       #print ('dschangeValeur', self.indexDernierLabel)
356
357       aLeFocus=self.focusWidget()
358       listeComplete=[]
359       libre=False
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==[]: 
366              libre=True
367              continue
368           validite,comm,comm2,listeRetour= self.politique.ajoutTuple(valeurTuple,listeComplete)
369           if not validite:
370              if comm2 != '' : comm += " " + comm2
371              self.editor.afficheInfos(comm+" "+str(self.objSimp.definition.validators.typeDesTuples),Qt.red)
372              return
373           listeComplete.append(tuple(courant.valeur))
374       #print ('listeComplete', listeComplete)
375       if listeComplete == [] : listeComplete=None
376       self.node.item.setValeur(listeComplete)
377
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 :
382           self.ajoutLineEdit()
383           self.listeAffichageWidget[-2].setFocus(True)
384       else :
385          try :
386            QApplication.processEvents()
387            w=self.listeAffichageWidget[self.listeAffichageWidget.index(aLeFocus)+1]
388            w.setFocus(True)
389            self.scrollArea.ensureWidgetVisible(w,0,0)
390          except :
391            pass
392           
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)
407
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
413
414         if len(liste)%self.nbValeurs != 0 :
415            texte="Nombre incorrect de valeurs"
416            self.editor.afficheInfos(tr(texte),Qt.red)
417            return
418
419         i=0
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)
424
425         min,max=self.node.item.getMinMax()
426         if self.objSimp.valeur == None : listeComplete=listeFormatee
427         else : listeComplete =self.objSimp.valeur + listeFormatee
428
429         if len(listeComplete) > max : 
430            texte=tr("Nombre maximum de valeurs ")+str(max)+tr(" atteint")
431            self.editor.afficheInfos(texte,Qt.red)
432            return
433
434         validite,comm,comm2,listeRetour= self.politique.ajoutNTuple(listeComplete)
435         if not validite : 
436            self.editor.afficheInfos(comm+comm2,Qt.red)
437            return
438
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
442
443         self.politique.recordValeur(listeComplete)
444
445         while ( i < len(liste) ) :
446             try :
447               t=tuple(liste[i:i+self.nbValeurs])
448             except:
449               t=tuple(liste[i:len(liste)])
450             i=i+self.nbValeurs
451             if indexDernierRempli < self.indexDernierLabel:
452
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]))
459             else : 
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)
463
464                nomCustomTuple='TupleCustom'+str(self.nbValeurs)
465                laClasseDuTuple=globals()[nomCustomTuple]
466                nouveauLE=laClasseDuTuple(self.nbValeurs,self.scrollArea,self,self.indexDernierLabel)
467                  
468                self.verticalLayoutLE.insertWidget(self.indexDernierLabel-1,nouveauLE)
469                setattr(self,nomLineEdit,nouveauLE)
470                nouveauLE.setValeur(t)
471
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
477
478         self.etablitOrdre()
479
480         
481
482   def RBListePush(self):
483   #----------------------
484   # PN a rendre generique avec un truc tel prerempli
485   # pour l instant specifique PSEN
486
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 :
495          val=[]
496          if  hasattr(self.objSimp.jdc,'LineDico'):
497           for k in self.objSimp.jdc.LineDico :
498               try :
499                valeur=self.objSimp.jdc.getConcept(k)
500                val.append((valeur,0))
501               except :
502                pass
503          self.node.item.setValeur(val)
504       if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_generateur :
505          val=[]
506          if  hasattr(self.objSimp.jdc,'MachineDico'):
507           for k in self.objSimp.jdc.MachineDico :
508               try :
509                valeur=self.objSimp.jdc.getConcept(k)
510                val.append((valeur,0))
511               except :
512                pass
513          self.node.item.setValeur(val)
514       if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_transfo :
515          val=[]
516          if  hasattr(self.objSimp.jdc,'TransfoDico'):
517           for k in self.objSimp.jdc.TransfoDico :
518               try :
519                valeur=self.objSimp.jdc.getConcept(k)
520                val.append((valeur,0))
521               except :
522                pass
523          self.node.item.setValeur(val)
524       if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_charge :
525          val=[]
526          if  hasattr(self.objSimp.jdc,'LoadDico'):
527           for k in self.objSimp.jdc.LoadDico :
528               try :
529                valeur=self.objSimp.jdc.getConcept(k)
530                val.append((valeur,0))
531               except :
532                pass
533          self.node.item.setValeur(val)
534       if self.objSimp.definition.validators.typeDesTuples[0]==self.editor.readercata.cata.sd_moteur :
535          val=[]
536          if  hasattr(self.objSimp.jdc,'MotorDico'):
537           for k in self.objSimp.jdc.MotorDico :
538               try :
539                valeur=self.objSimp.jdc.getConcept(k)
540                val.append((valeur,0))
541               except :
542                pass
543          self.node.item.setValeur(val)
544