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
33 from PyQt5.QtWidgets import QLineEdit, QLabel, QFileDialog
34 from PyQt5.QtCore import QEvent, Qt, QTimer
35 from PyQt5.QtGui import QIcon, QPalette
37 from Extensions.i18n import tr
38 from InterfaceQT4.monViewTexte import ViewText
41 # ---------------------- #
42 class LECustom(QLineEdit):
43 # ---------------------- #
44 def __init__(self,parent,parentQt,i):
48 QLineEdit.__init__(self,parent)
50 self.parentQt=parentQt
52 self.dansUnTuple=False
57 def focusInEvent(self,event):
58 #print ("dans focusInEvent de LECustom")
59 self.parentQt.aEuLeFocus=True
61 self.parentQt.LineEditEnCours=self
62 self.parentQt.numLineEditEnCours=self.num
63 self.parentQt.textSelected=self.text()
64 self.setStyleSheet("border: 2px solid gray")
65 QLineEdit.focusInEvent(self,event)
67 def focusOutEvent(self,event):
68 #print (self.aEuLeFocus)
69 self.setStyleSheet("border: 0px")
70 if self.dansUnTuple : self.setStyleSheet("background:rgb(235,235,235); border: 0px;")
71 elif self.num % 2 == 1 : self.setStyleSheet("background:rgb(210,210,210)")
72 else : self.setStyleSheet("background:rgb(235,235,235)")
76 if self.dansUnTuple : self.parentTuple.getValeur()
77 QLineEdit.focusOutEvent(self,event)
81 #print ("dans litValeur de LECustom")
84 if str(val)=="" or val==None :
91 d=self.parentQt.parentQt.objSimp.jdc.getContexteAvant(self.parentQt.objSimp. etape)
96 #print ('self.valeur', self.valeur)
106 def setValeur(self,valeur):
111 # --------------------------- #
112 class LECustomTuple(LECustom):
113 # --------------------------- #
114 def __init__(self,parent):
115 # index sera mis a jour par TupleCustom
116 parentQt=parent.parent().parent().parent()
117 LECustom. __init__(self,parent,parentQt,0)
120 # ---------------------------- #
121 class MonLabelListeClic(QLabel):
122 # ---------------------------- #
123 def __init__(self,parent):
124 QLabel.__init__(self,parent)
127 def event(self,event) :
128 if event.type() == QEvent.MouseButtonRelease:
129 self.texte=self.text()
130 self.parent.traiteClicSurLabelListe(self.texte)
131 return QLabel.event(self,event)
137 class GereListe(object):
141 self.connecterSignaux()
144 def connecterSignaux(self):
145 if hasattr(self,'RBHaut'):
146 self.RBHaut.clicked.connect(self.hautPushed)
147 self.RBBas.clicked.connect(self.basPushed)
148 self.RBMoins.clicked.connect(self.moinsPushed)
149 self.RBPlus.clicked.connect(self.plusPushed)
150 self.RBVoisListe.clicked.connect(self.voisListePushed)
151 if hasattr(self,'PBAlpha'):
152 self.PBCata.clicked.connect(self.cataPushed)
153 self.PBAlpha.clicked.connect(self.alphaPushed)
154 self.PBFind.clicked.connect(self.findPushed)
155 self.LEFiltre.returnPressed.connect(self.LEFiltreReturnPressed)
156 if hasattr(self, 'PBValideFeuille'):
157 self.PBValideFeuille.clicked.connect(self.changeValeur)
159 def filtreListe(self):
161 if self.filtre != "" :
162 for i in self.listeAAfficher :
163 if i.find(self.filtre) == 0 :l.append(i)
164 self.listeAAfficher=l
165 if self.alpha : self.listeAAfficher.sort()
167 def LEFiltreReturnPressed(self):
168 self.filtre= self.LEFiltre.text()
169 self.prepareListeResultatFiltre()
171 def findPushed(self):
172 self.filtre= self.LEFiltre.text()
173 self.prepareListeResultatFiltre()
175 def alphaPushed(self):
176 #print "alphaPushed" ,self.alpha
177 if self.alpha == 1 : return
179 self.prepareListeResultat()
181 def cataPushed(self):
182 if self.alpha == 0 : return
184 self.prepareListeResultat()
186 def hautPushed(self):
187 if self.numLineEditEnCours == 0 : return
188 if self.numLineEditEnCours == 1 : return
189 else : numEchange=self.numLineEditEnCours-1
190 self.echange(self.numLineEditEnCours,numEchange)
191 self.LineEditEnCours.setFocus(True)
192 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
196 if self.numLineEditEnCours == 0 : return
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)
211 #print (nomLineEdit2)
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()
259 if valeur=="" or valeur == None :
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(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()