1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 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
30 from .feuille import Feuille
31 from desWidgetPlusieursIntoOrdonne import Ui_WidgetPlusieursIntoOrdonne
32 from .politiquesValidation import PolitiquePlusieurs
33 from .qtSaisie import SaisieValeur
34 from .gereListe import GereListe
35 from .gereListe import GerePlie
36 from .gereListe import LECustom
37 from .gereListe import MonLabelListeClic
38 from Extensions.i18n import tr
40 from PyQt5.QtWidgets import QFrame, QApplication, QScrollBar
41 from PyQt5.QtCore import QTimer, QSize, Qt
42 from PyQt5.QtGui import QIcon, QPalette
45 class MonWidgetPlusieursIntoOrdonne (Ui_WidgetPlusieursIntoOrdonne, Feuille,GereListe,GerePlie):
47 def __init__(self,node,monSimpDef,nom,objSimp,parent,commande):
48 self.nomLine="LEResultat"
51 self.numLineEditEnCours=0
54 Feuille.__init__(self,node,monSimpDef,nom,objSimp,parent,commande)
55 GereListe.__init__(self)
56 #self.finCommentaireListe()
58 self.listeValeursCourantes=self.node.item.getListeValeurs()
60 self.maCommande.listeAffichageWidget.append(self.lineEditVal1)
62 # cas ou on ne peut rien ajouter
64 self.prepareListeResultat()
65 if len(self.listeAAfficher) < 20 : self.frameRecherche2.close()
66 if len(self.listeAAfficher) < 20 : self.frameRecherche.close()
68 #if sys.platform[0:5]!="linux":
69 repIcon=self.node.editor.appliEficas.repIcon
70 fichier=os.path.join(repIcon, 'arrow_up.png')
72 self.RBHaut.setIcon(icon)
73 self.RBHaut.setIconSize(QSize(32, 32))
74 fichier2=os.path.join(repIcon, 'arrow_down.png')
75 icon2 = QIcon(fichier2)
76 self.RBBas.setIcon(icon2)
77 icon=QIcon(self.repIcon+"/MoinsBleu.png")
78 self.RBMoins.setIcon(icon)
79 icon=QIcon(self.repIcon+"/PlusBleu.png")
80 self.RBPlus.setIcon(icon)
81 icon=QIcon(self.repIcon+"/verre-loupe-icone-6087-64.png")
82 self.RBVoisListe.setIcon(icon)
84 self.PBClean.clicked.connect(self.cleanListeResultatFiltre)
85 self.parentQt.commandesLayout.insertWidget(-1,self)
89 def prepareListeResultat(self):
90 for i in self.listeLE: i.close()
92 self.vScrollBar = self.scrollArea.verticalScrollBar()
93 self.listeValeursCourantes=self.node.item.getListeValeurs()
94 if hasattr(self.node.item.definition.validators,'set_MCSimp'):
95 obj=self.node.item.getObject()
96 self.node.item.definition.validators.set_MCSimp(obj)
97 if self.node.item.isValid() == 0 :
99 for item in self.listeValeursCourantes:
100 if self.node.item.definition.validators.verifItem(item)==1: liste.append(item)
101 self.listeAAfficher=self.node.item.getListePossible(liste)
103 self.listeAAfficher=self.node.item.getListePossible([])
105 self.listeAAfficher=self.node.item.getListePossible(self.listeValeursCourantes)
107 if self.listeAAfficher==[] :
111 if len(self.listeAAfficher)*20 > 400 : self.setMinimumHeight(400)
113 if self.monSimpDef.min > len(self.listeAAfficher) : self.setMinimumHeight(self.monSimpDef.min*30+300)
114 elif self.monSimpDef.max > len(self.listeAAfficher) : self.setMinimumHeight(400)
115 else : self.setMinimumHeight(len(self.listeAAfficher)*30+30)
116 self.setMinimumHeight(300)
119 self.politique=PolitiquePlusieurs(self.node,self.editor)
120 for i in range(1,len(self.listeAAfficher)+1): self.ajoutLE(i)
121 for i in range(len(self.listeAAfficher)):
122 nomLE="lineEditVal"+str(i+1)
123 courant=getattr(self,nomLE)
124 courant.setText(str(self.listeAAfficher[i]))
125 self.vScrollBar.triggerAction(QScrollBar.SliderToMinimum)
126 if len(self.listeAAfficher) < 15 and hasattr(self,'frameRecherche') : self.frameRecherche.close()
127 if len(self.listeAAfficher) < 15 and hasattr(self,'frameRecherche2') : self.frameRecherche2.close()
130 def setValeurs(self,first=True):
131 self.listeValeursCourantes=self.node.item.getListeValeurs()
133 if self.monSimpDef.max == "**" or self.monSimpDef.max == float('inf') : aConstruire=7
134 else : aConstruire=self.monSimpDef.max
135 if len(self.listeValeursCourantes) > aConstruire : aConstruire=len(self.listeValeursCourantes)
136 self.indexDernierLabel = aConstruire
137 for i in range(1,aConstruire+1): self.ajoutLEResultat(i)
139 for val in self.listeValeursCourantes :
140 nomLE="LEResultat"+str(index)
141 courant=getattr(self,nomLE)
142 courant.setText(str(val))
143 courant.setReadOnly(True)
145 while (index < self.indexDernierLabel) :
146 nomLE="LEResultat"+str(index)
147 courant=getattr(self,nomLE)
149 courant.setReadOnly(True)
151 #self.prepareListeResultat()
153 def moinsPushed(self):
154 self.ouAjouter=self.ouAjouter-1
155 GereListe.moinsPushed(self)
156 self.setValeurs(first=False)
158 def prepareListeResultatFiltre(self):
159 for i in self.listeRouge :
160 nomLE="lineEditVal"+str(i+1)
161 courant=getattr(self,nomLE)
163 palette = QPalette(Qt.black)
164 palette.setColor(QPalette.WindowText,Qt.black)
165 courant.setPalette(palette)
166 courant.setText(texte)
169 filtre=str(self.LEFiltre.text())
170 if filtre == '' : return
171 for i in range(len(self.listeAAfficher)):
172 nomLE="lineEditVal"+str(i+1)
173 courant=getattr(self,nomLE)
175 if texte.find(filtre) == 0 :
176 palette = QPalette(Qt.red)
177 palette.setColor(QPalette.WindowText,Qt.red)
178 courant.setPalette(palette)
179 courant.setText(texte)
180 self.listeRouge.append(i)
182 def cleanListeResultatFiltre(self):
183 self.LEFiltre.setText('')
184 self.prepareListeResultatFiltre()
186 def ajoutLEResultat (self,index,valeur=None):
187 #print ('ajoutLEResultat', index, valeur)
188 nomLE="LEResultat"+str(index)
189 if not (hasattr(self,nomLE)) :
190 nouveauLE = LECustom(self.scrollAreaRE,self,index)
191 nouveauLE.setFrame(False)
192 self.CBChoisis.insertWidget(self.ouAjouter,nouveauLE)
193 self.ouAjouter=self.ouAjouter+1
194 nouveauLE.setReadOnly(True)
195 if index % 2 == 1 : nouveauLE.setStyleSheet("background:rgb(210,210,210)")
196 else : nouveauLE.setStyleSheet("background:rgb(240,240,240)")
197 self.vScrollBarRE = self.scrollAreaRE.verticalScrollBar()
198 self.vScrollBarRE.triggerAction(QScrollBar.SliderToMaximum)
199 setattr(self,nomLE,nouveauLE)
200 self.estVisibleRE=nouveauLE
202 nouveauLE=getattr(self,nomLE)
204 if valeur == None : nouveauLE.setText("")
205 else : nouveauLE.setText(str(valeur))
207 def ajoutLE(self,index,valeur=None):
209 nomLE="lineEditVal"+str(index)
210 nouveauLE = MonLabelListeClic(self)
211 #self.CBLayout.addWidget(nouveauLE)
212 self.CBLayout.insertWidget(index -1,nouveauLE)
213 self.listeLE.append(nouveauLE)
214 nouveauLE.setFrameShape(QFrame.NoFrame)
215 QApplication.processEvents()
216 nouveauLE.setText("")
217 if index % 2 == 1 : nouveauLE.setStyleSheet("background:rgb(210,210,210)")
218 else : nouveauLE.setStyleSheet("background:rgb(240,240,240)")
219 self.vScrollBar.triggerAction(QScrollBar.SliderToMaximum)
221 setattr(self,nomLE,nouveauLE)
223 def ajoutLineEdit(self):
224 #print ('ajoutLineEdit')
225 self.indexDernierLabel=self.indexDernierLabel+1
226 self.ajoutLEResultat (self.indexDernierLabel)
229 def traiteClicSurLabelListe(self,valeur):
230 if valeur == None : return
231 liste,validite=SaisieValeur.TraiteLEValeur(self,str(valeur))
232 if validite == 0 : return
233 if liste ==[] : return
236 self.listeValeursCourantes=self.node.item.getListeValeurs()
237 min,max = self.node.item.getMinMax()
238 if len(self.listeValeursCourantes) +1 > max :
239 self.editor.afficheInfos(tr("Nombre maximal de valeurs : ") + str(max),Qt.red)
242 self.editor.afficheInfos("")
245 for i in range(1,self.indexDernierLabel+1):
246 nomLE="LEResultat"+str(i)
247 courant=getattr(self,nomLE)
248 if str(courant.text())==str("") :
249 courant.setText(valeur)
250 courant.setReadOnly(True)
252 self.estVisibleRE=courant
253 QTimer.singleShot(1, self.rendVisibleLigneRE)
257 self.indexDernierLabel = self.indexDernierLabel+1
258 self.ajoutLEResultat (self.indexDernierLabel,str(valeur))
259 self.vScrollBarRE.triggerAction(QScrollBar.SliderToMaximum)
260 QTimer.singleShot(1, self.rendVisibleLigneRE)
262 self.setValeurs(first=False)
264 def changeValeur(self,changeDePlace=False,oblige=False):
265 #def changeValeur(self,changeDePlace=False,oblige=False, numero=None):
266 #PN les 2 arg sont pour que la signature de ma fonction soit identique a monWidgetPlusieursBase
268 for i in range(1,self.indexDernierLabel+1):
269 nomLE="LEResultat"+str(i)
270 courant=getattr(self,nomLE)
271 valeur=courant.text()
272 if str(valeur)=="" : continue
273 liste,validite=SaisieValeur.TraiteLEValeur(self,str(valeur))
274 listeVal.append(str(valeur))
276 validite,comm,comm2,listeRetour=self.politique.ajoutValeurs(listeVal,-1,[])
279 self.listeValeursCourantes=self.node.item.getListeValeurs()
280 min,max = self.node.item.getMinMax()
281 if len(self.listeValeursCourantes) < min :
282 self.editor.afficheInfos(tr("Nombre minimal de valeurs : ") + str(min),Qt.red)
284 self.editor.afficheInfos("")
286 if len(listeRetour) == 0 :
287 self.node.item.setValeur(None)
289 self.node.item.setValeur(listeRetour)
291 commentaire=comm+" "+comm2
292 self.editor.afficheInfos(commentaire,Qt.red)
297 def rendVisibleLigneRE(self):
298 QApplication.processEvents()
299 self.estVisibleRE.setFocus()
300 self.scrollArea.ensureWidgetVisible(self.estVisibleRE,0,0)
302 def rendVisibleLigne(self):
303 self.estVisibleRE=self.estVisible
304 #rendVisibleLigneRE()