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)")
72 if isinstance(self,LECustomTuple) and not self.tupleCustomParent.inFocusOutEvent:
73 self.tupleCustomParent.inFocusOutEvent=True
74 self.tupleCustomParent.valueChange()
75 self.tupleCustomParent.inFocusOutEvent=False
76 QLineEdit.focusOutEvent(self,event)
84 def setValeur(self,valeur):
89 # --------------------------- #
90 class LECustomTuple(LECustom):
91 # --------------------------- #
92 def __init__(self,parent):
93 # index sera mis a jour par TupleCustom
94 parentQt=parent.parent().parent().parent()
95 LECustom. __init__(self,parent,parentQt,0)
98 # ---------------------------- #
99 class MonLabelListeClic(QLabel):
100 # ---------------------------- #
101 def __init__(self,parent):
102 QLabel.__init__(self,parent)
105 def event(self,event) :
106 if event.type() == QEvent.MouseButtonRelease:
107 self.texte=self.text()
108 self.parent.traiteClicSurLabelListe(self.texte)
109 return QLabel.event(self,event)
115 class GereListe(object):
119 self.connecterSignaux()
121 def connecterSignauxQT4(self):
122 if hasattr(self,'RBHaut'):
123 self.connect(self.RBHaut,SIGNAL("clicked()"),self.hautPushed)
124 self.connect(self.RBBas,SIGNAL("clicked()"),self.basPushed)
125 self.connect(self.RBMoins,SIGNAL("clicked()"),self.moinsPushed)
126 self.connect(self.RBPlus,SIGNAL("clicked()"),self.plusPushed)
127 self.connect(self.RBVoisListe,SIGNAL("clicked()"),self.voisListePushed)
128 if hasattr(self,'PBAlpha'):
129 self.connect(self.PBAlpha,SIGNAL("clicked()"),self.alphaPushed)
130 self.connect(self.PBCata,SIGNAL("clicked()"),self.cataPushed)
131 self.connect(self.PBFind,SIGNAL("clicked()"),self.findPushed)
132 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.LEFiltreReturnPressed)
134 def connecterSignaux(self):
135 if hasattr(self,'RBHaut'):
136 self.RBHaut.clicked.connect(self.hautPushed)
137 self.RBBas.clicked.connect(self.basPushed)
138 self.RBMoins.clicked.connect(self.moinsPushed)
139 self.RBPlus.clicked.connect(self.plusPushed)
140 self.RBVoisListe.clicked.connect(self.voisListePushed)
141 if hasattr(self,'PBAlpha'):
142 self.PBCata.clicked.connect(self.cataPushed)
143 self.PBAlpha.clicked.connect(self.alphaPushed)
144 self.PBFind.clicked.connect(self.findPushed)
145 self.LEFiltre.returnPressed.connect(self.LEFiltreReturnPressed)
147 def filtreListe(self):
149 if self.filtre != "" :
150 for i in self.listeAAfficher :
151 if i.find(self.filtre) == 0 :l.append(i)
152 self.listeAAfficher=l
153 if self.alpha : self.listeAAfficher.sort()
155 def LEFiltreReturnPressed(self):
156 self.filtre= self.LEFiltre.text()
157 self.prepareListeResultatFiltre()
159 def findPushed(self):
160 self.filtre= self.LEFiltre.text()
161 self.prepareListeResultatFiltre()
163 def alphaPushed(self):
164 #print "alphaPushed" ,self.alpha
165 if self.alpha == 1 : return
167 self.prepareListeResultat()
169 def cataPushed(self):
170 if self.alpha == 0 : return
172 self.prepareListeResultat()
174 def hautPushed(self):
175 if self.NumLineEditEnCours == 1 : return
176 else : numEchange=self.NumLineEditEnCours-1
177 self.echange(self.NumLineEditEnCours,numEchange)
178 self.LineEditEnCours.setFocus(True)
179 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
183 if self.NumLineEditEnCours == self.indexDernierLabel : return
184 else : numEchange=self.NumLineEditEnCours+1
185 self.echange(self.NumLineEditEnCours,numEchange)
186 self.LineEditEnCours.setFocus(True)
187 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
189 def echange(self,num1,num2):
190 # on donne le focus au a celui ou on a bouge
191 # par convention le 2
192 nomLineEdit=self.nomLine+str(num1)
194 courant=getattr(self,nomLineEdit)
195 valeurAGarder=courant.text()
196 nomLineEdit2=self.nomLine+str(num2)
198 courant2=getattr(self,nomLineEdit2)
199 courant.setText(courant2.text())
200 courant2.setText(valeurAGarder)
201 self.changeValeur(changeDePlace=False)
202 self.NumLineEditEnCours=num2
203 self.LineEditEnCours=courant2
204 self.LineEditEnCours.setFocus(True)
206 def moinsPushed(self):
207 # on supprime le dernier
208 if self.NumLineEditEnCours == 0 : return
209 if self.NumLineEditEnCours==self.indexDernierLabel :
210 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
211 courant=getattr(self,nomLineEdit)
214 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
216 nomLineEdit=self.nomLine+str(aRemonter)
217 courant=getattr(self,nomLineEdit)
218 valeurARemonter=courant.getValeur()
219 nomLineEdit=self.nomLine+str(i)
220 courant=getattr(self,nomLineEdit)
221 if valeurARemonter != None : courant.setValeur(valeurARemonter)
222 else : courant.clean()
223 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
224 courant=getattr(self,nomLineEdit)
226 self.changeValeur(changeDePlace=False,oblige=True)
229 def plusPushed(self):
230 if self.indexDernierLabel == self.monSimpDef.max:
231 if len(self.listeValeursCourantes) < self.monSimpDef.max : self.chercheLigneVide()
232 else : self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
235 self.descendLesLignes()
237 def chercheLigneVide(self):
238 for i in range(self.indexDernierLabel) :
239 nomLineEdit=self.nomLine+str(i+1)
240 courant=getattr(self,nomLineEdit)
241 valeur=courant.getValeur()
242 if valeur=="" : courant.setFocus(7);return
245 def descendLesLignes(self):
246 if self.NumLineEditEnCours==self.indexDernierLabel : return
247 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
248 courant=getattr(self,nomLineEdit)
249 valeurADescendre=courant.getValeur()
251 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
253 nomLineEdit=self.nomLine+str(aDescendre)
254 courant=getattr(self,nomLineEdit)
255 valeurAGarder=courant.getValeur()
256 courant.setValeur(valeurADescendre)
257 valeurADescendre=valeurAGarder
258 self.changeValeur(changeDePlace=False)
259 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
261 def voisListePushed(self):
263 for v in self.node.item.GetListeValeurs():
264 texteValeurs+=str(v)+", "
265 entete="Valeurs pour "+self.nom
266 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
270 def selectInFile(self):
271 init=str( self.editor.CONFIGURATION.savedir)
272 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
273 tr("Fichier de donnees"),
275 tr('Tous les Fichiers (*)',))
277 if fn == None : return
279 ulfile = os.path.abspath(six.text_type(fn))
280 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
282 from .monSelectVal import MonSelectVal
283 MonSelectVal(file=fn,parent=self).show()
285 def noircirResultatFiltre(self):
286 filtre=str(self.LEFiltre.text())
287 for cb in self.listeCbRouge:
288 palette = QPalette(Qt.red)
289 palette.setColor(QPalette.WindowText,Qt.black)
290 cb.setPalette(palette)
293 self.LEFiltre.setText("")
294 self.listeCbRouge = []
298 class GerePlie(object):
301 def gereIconePlier(self):
302 if not(hasattr(self,'BFermeListe')) : return
303 self.editor.listeDesListesOuvertes.add(self.node.item)
304 repIcon=self.node.editor.appliEficas.repIcon
305 if not (self.editor.afficheListesPliees):
306 fichier=os.path.join(repIcon, 'empty.png')
307 icon = QIcon(fichier)
308 self.BFermeListe.setIcon(icon)
310 fichier=os.path.join(repIcon, 'minusnode.png')
311 icon = QIcon(fichier)
312 self.BFermeListe.setIcon(icon)
313 self.BFermeListe.clicked.connect( self.selectWidgetPlie)
315 def selectWidgetPlie(self):
316 self.editor.listeDesListesOuvertes.remove(self.node.item)
317 self.reaffichePourDeplier()