1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 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
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
57 def focusInEvent(self,event):
58 #print "dans focusInEvent de LECustom"
59 self.parentQt.LineEditEnCours=self
60 self.parentQt.NumLineEditEnCours=self.num
61 self.parentQt.textSelected=self.text()
62 self.setStyleSheet("border: 2px solid gray")
63 QLineEdit.focusInEvent(self,event)
65 def focusOutEvent(self,event):
66 self.setStyleSheet("border: 0px")
67 if self.dansUnTuple : self.setStyleSheet("background:rgb(235,235,235); border: 0px;")
68 elif self.num % 2 == 1 : self.setStyleSheet("background:rgb(210,210,210)")
69 else : self.setStyleSheet("background:rgb(235,235,235)")
73 from InterfaceQT4.monWidgetPlusieursBase import MonWidgetPlusieursBase
75 #if isinstance (self.parentQt, MonWidgetPlusieursBase) and not self.parentQt.inFocusOutEvent :
76 # self.parentQt.inFocusOutEvent=True
77 # self.parentQt.changeValeur(changeDePlace=True,oblige=False)
78 # self.parentQt.inFocusOutEvent=False
80 #if isinstance(self,LECustomTuple) and not self.tupleCustomParent.inFocusOutEvent:
81 # self.tupleCustomParent.inFocusOutEvent=True
82 # self.tupleCustomParent.valueChange()
83 # self.tupleCustomParent.inFocusOutEvent=False
84 QLineEdit.focusOutEvent(self,event)
93 def setValeur(self,valeur):
98 # --------------------------- #
99 class LECustomTuple(LECustom):
100 # --------------------------- #
101 def __init__(self,parent):
102 # index sera mis a jour par TupleCustom
103 parentQt=parent.parent().parent().parent()
104 LECustom. __init__(self,parent,parentQt,0)
107 # ---------------------------- #
108 class MonLabelListeClic(QLabel):
109 # ---------------------------- #
110 def __init__(self,parent):
111 QLabel.__init__(self,parent)
114 def event(self,event) :
115 if event.type() == QEvent.MouseButtonRelease:
116 self.texte=self.text()
117 self.parent.traiteClicSurLabelListe(self.texte)
118 return QLabel.event(self,event)
124 class GereListe(object):
128 self.connecterSignaux()
130 def connecterSignauxQT4(self):
131 if hasattr(self,'RBHaut'):
132 self.connect(self.RBHaut,SIGNAL("clicked()"),self.hautPushed)
133 self.connect(self.RBBas,SIGNAL("clicked()"),self.basPushed)
134 self.connect(self.RBMoins,SIGNAL("clicked()"),self.moinsPushed)
135 self.connect(self.RBPlus,SIGNAL("clicked()"),self.plusPushed)
136 self.connect(self.RBVoisListe,SIGNAL("clicked()"),self.voisListePushed)
137 if hasattr(self,'PBAlpha'):
138 self.connect(self.PBAlpha,SIGNAL("clicked()"),self.alphaPushed)
139 self.connect(self.PBCata,SIGNAL("clicked()"),self.cataPushed)
140 self.connect(self.PBFind,SIGNAL("clicked()"),self.findPushed)
141 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.LEFiltreReturnPressed)
143 def connecterSignaux(self):
144 if hasattr(self,'RBHaut'):
145 self.RBHaut.clicked.connect(self.hautPushed)
146 self.RBBas.clicked.connect(self.basPushed)
147 self.RBMoins.clicked.connect(self.moinsPushed)
148 self.RBPlus.clicked.connect(self.plusPushed)
149 self.RBVoisListe.clicked.connect(self.voisListePushed)
150 if hasattr(self,'PBAlpha'):
151 self.PBCata.clicked.connect(self.cataPushed)
152 self.PBAlpha.clicked.connect(self.alphaPushed)
153 self.PBFind.clicked.connect(self.findPushed)
154 self.LEFiltre.returnPressed.connect(self.LEFiltreReturnPressed)
156 def filtreListe(self):
158 if self.filtre != "" :
159 for i in self.listeAAfficher :
160 if i.find(self.filtre) == 0 :l.append(i)
161 self.listeAAfficher=l
162 if self.alpha : self.listeAAfficher.sort()
164 def LEFiltreReturnPressed(self):
165 self.filtre= self.LEFiltre.text()
166 self.prepareListeResultatFiltre()
168 def findPushed(self):
169 self.filtre= self.LEFiltre.text()
170 self.prepareListeResultatFiltre()
172 def alphaPushed(self):
173 #print "alphaPushed" ,self.alpha
174 if self.alpha == 1 : return
176 self.prepareListeResultat()
178 def cataPushed(self):
179 if self.alpha == 0 : return
181 self.prepareListeResultat()
183 def hautPushed(self):
184 if self.NumLineEditEnCours == 1 : return
185 else : numEchange=self.NumLineEditEnCours-1
186 self.echange(self.NumLineEditEnCours,numEchange)
187 self.LineEditEnCours.setFocus(True)
188 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
192 if self.NumLineEditEnCours == self.indexDernierLabel : return
193 else : numEchange=self.NumLineEditEnCours+1
194 self.echange(self.NumLineEditEnCours,numEchange)
195 self.LineEditEnCours.setFocus(True)
196 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
198 def echange(self,num1,num2):
199 # on donne le focus au a celui ou on a bouge
200 # par convention le 2
201 nomLineEdit=self.nomLine+str(num1)
203 courant=getattr(self,nomLineEdit)
204 valeurAGarder=courant.text()
205 nomLineEdit2=self.nomLine+str(num2)
207 courant2=getattr(self,nomLineEdit2)
208 courant.setText(courant2.text())
209 courant2.setText(valeurAGarder)
210 self.changeValeur(changeDePlace=False)
211 self.NumLineEditEnCours=num2
212 self.LineEditEnCours=courant2
213 self.LineEditEnCours.setFocus(True)
215 def moinsPushed(self):
216 # on supprime le dernier
217 if self.NumLineEditEnCours == 0 : return
218 if self.indexDernierLabel == 0 : return
219 if self.NumLineEditEnCours==self.indexDernierLabel :
220 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
221 courant=getattr(self,nomLineEdit)
224 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
226 nomLineEdit=self.nomLine+str(aRemonter)
227 courant=getattr(self,nomLineEdit)
228 valeurARemonter=courant.getValeur()
229 nomLineEdit=self.nomLine+str(i)
230 courant=getattr(self,nomLineEdit)
231 if valeurARemonter != None : courant.setValeur(valeurARemonter)
232 else : courant.clean()
233 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
234 courant=getattr(self,nomLineEdit)
236 self.changeValeur(changeDePlace=False,oblige=True)
239 def plusPushed(self):
240 if self.indexDernierLabel == self.monSimpDef.max:
241 if len(self.listeValeursCourantes) < self.monSimpDef.max : self.chercheLigneVide()
242 else : self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
245 self.descendLesLignes()
247 def chercheLigneVide(self):
248 for i in range(self.indexDernierLabel) :
249 nomLineEdit=self.nomLine+str(i+1)
250 courant=getattr(self,nomLineEdit)
251 valeur=courant.getValeur()
252 if valeur=="" : courant.setFocus(7);return
255 def descendLesLignes(self):
256 if self.NumLineEditEnCours==self.indexDernierLabel : return
257 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
258 courant=getattr(self,nomLineEdit)
259 valeurADescendre=courant.getValeur()
261 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
263 nomLineEdit=self.nomLine+str(aDescendre)
264 courant=getattr(self,nomLineEdit)
265 valeurAGarder=courant.getValeur()
266 courant.setValeur(valeurADescendre)
267 valeurADescendre=valeurAGarder
268 self.changeValeur(changeDePlace=False)
269 if hasattr (self, 'LineEditEnCours') :self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
271 def voisListePushed(self):
273 for v in self.node.item.GetListeValeurs():
274 texteValeurs+=str(v)+", "
275 entete="Valeurs pour "+self.nom
276 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
280 def selectInFile(self):
281 init=str( self.editor.CONFIGURATION.savedir)
282 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
283 tr("Fichier de donnees"),
285 tr('Tous les Fichiers (*)',))
287 if fn == None : return
289 ulfile = os.path.abspath(six.text_type(fn))
290 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
292 from .monSelectVal import MonSelectVal
293 MonSelectVal(file=fn,parent=self).show()
295 def noircirResultatFiltre(self):
296 filtre=str(self.LEFiltre.text())
297 for cb in self.listeCbRouge:
298 palette = QPalette(Qt.red)
299 palette.setColor(QPalette.WindowText,Qt.black)
300 cb.setPalette(palette)
303 self.LEFiltre.setText("")
304 self.listeCbRouge = []
308 class GerePlie(object):
311 def gereIconePlier(self):
312 if not(hasattr(self,'BFermeListe')) : return
313 self.editor.listeDesListesOuvertes.add(self.node.item)
314 repIcon=self.node.editor.appliEficas.repIcon
315 if not (self.editor.afficheListesPliees):
316 fichier=os.path.join(repIcon, 'empty.png')
317 icon = QIcon(fichier)
318 self.BFermeListe.setIcon(icon)
320 fichier=os.path.join(repIcon, 'minusnode.png')
321 icon = QIcon(fichier)
322 self.BFermeListe.setIcon(icon)
323 self.BFermeListe.clicked.connect( self.selectWidgetPlie)
325 def selectWidgetPlie(self):
326 self.editor.listeDesListesOuvertes.remove(self.node.item)
327 self.reaffichePourDeplier()