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
22 from __future__ import absolute_import
24 from builtins import str
25 from builtins import range
26 from builtins import object
34 from six.moves import range
35 from PyQt5.QtWidgets import QLineEdit, QLabel, QFileDialog
36 from PyQt5.QtCore import QEvent, Qt, QTimer
37 from PyQt5.QtGui import QIcon, QPalette
39 from Extensions.i18n import tr
40 from InterfaceQT4.monViewTexte import ViewText
43 # ---------------------- #
44 class LECustom(QLineEdit):
45 # ---------------------- #
46 def __init__(self,parent,parentQt,i):
50 QLineEdit.__init__(self,parent)
52 self.parentQt=parentQt
54 self.dansUnTuple=False
59 def focusInEvent(self,event):
60 #print ("dans focusInEvent de LECustom")
61 self.parentQt.aEuLeFocus=True
63 self.parentQt.LineEditEnCours=self
64 self.parentQt.numLineEditEnCours=self.num
65 self.parentQt.textSelected=self.text()
66 self.setStyleSheet("border: 2px solid gray")
67 QLineEdit.focusInEvent(self,event)
69 def focusOutEvent(self,event):
70 #print (self.aEuLeFocus)
71 self.setStyleSheet("border: 0px")
72 if self.dansUnTuple : self.setStyleSheet("background:rgb(235,235,235); border: 0px;")
73 elif self.num % 2 == 1 : self.setStyleSheet("background:rgb(210,210,210)")
74 else : self.setStyleSheet("background:rgb(235,235,235)")
78 if self.dansUnTuple : self.parentTuple.getValeur()
79 QLineEdit.focusOutEvent(self,event)
83 #print ("dans litValeur de LECustom")
86 if str(val)=="" or val==None :
93 d=self.parentQt.parentQt.objSimp.jdc.getContexteAvant(self.parentQt.objSimp. etape)
98 #print ('self.valeur', self.valeur)
108 def setValeur(self,valeur):
113 # --------------------------- #
114 class LECustomTuple(LECustom):
115 # --------------------------- #
116 def __init__(self,parent):
117 # index sera mis a jour par TupleCustom
118 parentQt=parent.parent().parent().parent()
119 LECustom. __init__(self,parent,parentQt,0)
122 # ---------------------------- #
123 class MonLabelListeClic(QLabel):
124 # ---------------------------- #
125 def __init__(self,parent):
126 QLabel.__init__(self,parent)
129 def event(self,event) :
130 if event.type() == QEvent.MouseButtonRelease:
131 self.texte=self.text()
132 self.parent.traiteClicSurLabelListe(self.texte)
133 return QLabel.event(self,event)
139 class GereListe(object):
143 self.connecterSignaux()
146 def connecterSignaux(self):
147 if hasattr(self,'RBHaut'):
148 self.RBHaut.clicked.connect(self.hautPushed)
149 self.RBBas.clicked.connect(self.basPushed)
150 self.RBMoins.clicked.connect(self.moinsPushed)
151 self.RBPlus.clicked.connect(self.plusPushed)
152 self.RBVoisListe.clicked.connect(self.voisListePushed)
153 if hasattr(self,'PBAlpha'):
154 self.PBCata.clicked.connect(self.cataPushed)
155 self.PBAlpha.clicked.connect(self.alphaPushed)
156 self.PBFind.clicked.connect(self.findPushed)
157 self.LEFiltre.returnPressed.connect(self.LEFiltreReturnPressed)
158 if hasattr(self, 'PBValideFeuille'):
159 self.PBValideFeuille.clicked.connect(self.changeValeur)
161 def filtreListe(self):
163 if self.filtre != "" :
164 for i in self.listeAAfficher :
165 if i.find(self.filtre) == 0 :l.append(i)
166 self.listeAAfficher=l
167 if self.alpha : self.listeAAfficher.sort()
169 def LEFiltreReturnPressed(self):
170 self.filtre= self.LEFiltre.text()
171 self.prepareListeResultatFiltre()
173 def findPushed(self):
174 self.filtre= self.LEFiltre.text()
175 self.prepareListeResultatFiltre()
177 def alphaPushed(self):
178 #print "alphaPushed" ,self.alpha
179 if self.alpha == 1 : return
181 self.prepareListeResultat()
183 def cataPushed(self):
184 if self.alpha == 0 : return
186 self.prepareListeResultat()
188 def hautPushed(self):
189 if self.numLineEditEnCours == 1 : return
190 else : numEchange=self.numLineEditEnCours-1
191 self.echange(self.numLineEditEnCours,numEchange)
192 self.LineEditEnCours.setFocus(True)
193 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
197 if self.numLineEditEnCours == self.indexDernierLabel : return
198 else : numEchange=self.numLineEditEnCours+1
199 self.echange(self.numLineEditEnCours,numEchange)
200 self.LineEditEnCours.setFocus(True)
201 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
203 def echange(self,num1,num2):
204 # on donne le focus au a celui ou on a bouge
205 # par convention le 2
206 nomLineEdit=self.nomLine+str(num1)
208 courant=getattr(self,nomLineEdit)
209 valeurAGarder=courant.text()
210 nomLineEdit2=self.nomLine+str(num2)
212 courant2=getattr(self,nomLineEdit2)
213 courant.setText(courant2.text())
214 courant2.setText(valeurAGarder)
215 self.changeValeur(changeDePlace=False)
216 self.numLineEditEnCours=num2
217 self.LineEditEnCours=courant2
218 self.LineEditEnCours.setFocus(True)
220 def moinsPushed(self):
221 # on supprime le dernier
222 if self.numLineEditEnCours == 0 : return
223 if self.indexDernierLabel == 0 : return
224 if self.numLineEditEnCours==self.indexDernierLabel :
225 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
226 courant=getattr(self,nomLineEdit)
229 for i in range (self.numLineEditEnCours, self.indexDernierLabel):
231 nomLineEdit=self.nomLine+str(aRemonter)
232 courant=getattr(self,nomLineEdit)
233 valeurARemonter=courant.getValeur()
234 nomLineEdit=self.nomLine+str(i)
235 courant=getattr(self,nomLineEdit)
236 if valeurARemonter != None : courant.setValeur(valeurARemonter)
237 else : courant.clean()
238 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
239 courant=getattr(self,nomLineEdit)
241 self.changeValeur(changeDePlace=False,oblige=True)
244 def plusPushed(self):
245 if self.indexDernierLabel == self.monSimpDef.max:
246 if len(self.listeValeursCourantes) < self.monSimpDef.max : self.chercheLigneVide()
247 else : self.editor.afficheInfos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
250 self.descendLesLignes()
251 self.chercheLigneVide()
252 QTimer.singleShot(1, self.rendVisibleLigne)
254 def chercheLigneVide(self):
255 for i in range(self.indexDernierLabel) :
256 nomLineEdit=self.nomLine+str(i+1)
257 courant=getattr(self,nomLineEdit)
258 valeur=courant.getValeur()
260 courant.setFocus(True)
261 self.estVisible=courant
265 def descendLesLignes(self):
266 if self.numLineEditEnCours==self.indexDernierLabel : return
267 nomLineEdit=self.nomLine+str(self.numLineEditEnCours+1)
268 courant=getattr(self,nomLineEdit)
269 valeurADescendre=courant.getValeur()
271 for i in range (self.numLineEditEnCours+1, self.indexDernierLabel):
273 nomLineEdit=self.nomLine+str(aDescendre)
274 courant=getattr(self,nomLineEdit)
275 valeurAGarder=courant.getValeur()
276 courant.setValeur(valeurADescendre)
277 valeurADescendre=valeurAGarder
278 self.changeValeur(changeDePlace=False)
279 if hasattr (self, 'LineEditEnCours') :self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
281 def voisListePushed(self):
283 for v in self.node.item.getListeValeurs():
284 texteValeurs+=str(v)+", "
285 entete="Valeurs pour "+self.nom
286 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
290 def selectInFile(self):
291 init=str( self.editor.maConfiguration.savedir)
292 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
293 tr("Fichier de donnees"),
295 tr('Tous les Fichiers (*)',))
297 if fn == None : return
299 ulfile = os.path.abspath(six.text_type(fn))
300 self.editor.maConfiguration.savedir=os.path.split(ulfile)[0]
302 from .monSelectVal import MonSelectVal
303 MonSelectVal(file=fn,parent=self).show()
305 def noircirResultatFiltre(self):
306 filtre=str(self.LEFiltre.text())
307 for cb in self.listeCbRouge:
308 palette = QPalette(Qt.red)
309 palette.setColor(QPalette.WindowText,Qt.black)
310 cb.setPalette(palette)
313 self.LEFiltre.setText("")
314 self.listeCbRouge = []
318 class GerePlie(object):
321 def gereIconePlier(self):
322 if not(hasattr(self,'BFermeListe')) : return
323 self.editor.listeDesListesOuvertes.add(self.node.item)
324 repIcon=self.node.editor.appliEficas.repIcon
325 if not (self.editor.afficheListesPliees):
326 fichier=os.path.join(repIcon, 'empty.png')
327 icon = QIcon(fichier)
328 self.BFermeListe.setIcon(icon)
330 fichier=os.path.join(repIcon, 'minusnode.png')
331 icon = QIcon(fichier)
332 self.BFermeListe.setIcon(icon)
333 self.BFermeListe.clicked.connect( self.selectWidgetPlie)
335 def selectWidgetPlie(self):
336 self.editor.listeDesListesOuvertes.remove(self.node.item)
337 self.reaffichePourDeplier()