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)
51 self.parentQt=parentQt
53 self.dansUnTuple=False
55 def focusInEvent(self,event):
56 #print "dans focusInEvent de LECustom"
57 self.parentQt.LineEditEnCours=self
58 self.parentQt.NumLineEditEnCours=self.num
59 self.parentQt.textSelected=self.text()
60 self.setStyleSheet("border: 2px solid gray")
61 QLineEdit.focusInEvent(self,event)
63 def focusOutEvent(self,event):
64 #print "dans focusOutEvent de LECustom"
65 self.setStyleSheet("border: 0px")
66 if self.dansUnTuple : self.setStyleSheet("background:rgb(235,235,235); border: 0px;")
67 elif self.num % 2 == 1 : self.setStyleSheet("background:rgb(210,210,210)")
68 else : self.setStyleSheet("background:rgb(235,235,235)")
69 QLineEdit.focusOutEvent(self,event)
77 def setValeur(self,valeur):
82 # --------------------------- #
83 class LECustomTuple(LECustom):
84 # --------------------------- #
85 def __init__(self,parent):
86 # index sera mis a jour par TupleCustom
87 parentQt=parent.parent().parent().parent()
88 LECustom. __init__(self,parent,parentQt,0)
90 # ---------------------------- #
91 class MonLabelListeClic(QLabel):
92 # ---------------------------- #
93 def __init__(self,parent):
94 QLabel.__init__(self,parent)
97 def event(self,event) :
98 if event.type() == QEvent.MouseButtonRelease:
99 self.texte=self.text()
100 self.parent.traiteClicSurLabelListe(self.texte)
101 return QLabel.event(self,event)
107 class GereListe(object):
111 self.connecterSignaux()
113 def connecterSignauxQT4(self):
114 if hasattr(self,'RBHaut'):
115 self.connect(self.RBHaut,SIGNAL("clicked()"),self.hautPushed)
116 self.connect(self.RBBas,SIGNAL("clicked()"),self.basPushed)
117 self.connect(self.RBMoins,SIGNAL("clicked()"),self.moinsPushed)
118 self.connect(self.RBPlus,SIGNAL("clicked()"),self.plusPushed)
119 self.connect(self.RBVoisListe,SIGNAL("clicked()"),self.voisListePushed)
120 if hasattr(self,'PBAlpha'):
121 self.connect(self.PBAlpha,SIGNAL("clicked()"),self.alphaPushed)
122 self.connect(self.PBCata,SIGNAL("clicked()"),self.cataPushed)
123 self.connect(self.PBFind,SIGNAL("clicked()"),self.findPushed)
124 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.LEFiltreReturnPressed)
126 def connecterSignaux(self):
127 if hasattr(self,'RBHaut'):
128 self.RBHaut.clicked.connect(self.hautPushed)
129 self.RBBas.clicked.connect(self.basPushed)
130 self.RBMoins.clicked.connect(self.moinsPushed)
131 self.RBPlus.clicked.connect(self.plusPushed)
132 self.RBVoisListe.clicked.connect(self.voisListePushed)
133 if hasattr(self,'PBAlpha'):
134 self.PBCata.clicked.connect(self.cataPushed)
135 self.PBAlpha.clicked.connect(self.alphaPushed)
136 self.PBFind.clicked.connect(self.findPushed)
137 self.LEFiltre.returnPressed.connect(self.LEFiltreReturnPressed)
139 def filtreListe(self):
141 if self.filtre != "" :
142 for i in self.listeAAfficher :
143 if i.find(self.filtre) == 0 :l.append(i)
144 self.listeAAfficher=l
145 if self.alpha : self.listeAAfficher.sort()
147 def LEFiltreReturnPressed(self):
148 self.filtre= self.LEFiltre.text()
149 self.prepareListeResultatFiltre()
151 def findPushed(self):
152 self.filtre= self.LEFiltre.text()
153 self.prepareListeResultatFiltre()
155 def alphaPushed(self):
156 #print "alphaPushed" ,self.alpha
157 if self.alpha == 1 : return
159 self.prepareListeResultat()
161 def cataPushed(self):
162 if self.alpha == 0 : return
164 self.prepareListeResultat()
166 def hautPushed(self):
167 if self.NumLineEditEnCours == 1 : return
168 else : numEchange=self.NumLineEditEnCours-1
169 self.echange(self.NumLineEditEnCours,numEchange)
170 self.LineEditEnCours.setFocus(True)
171 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
175 if self.NumLineEditEnCours == self.indexDernierLabel : return
176 else : numEchange=self.NumLineEditEnCours+1
177 self.echange(self.NumLineEditEnCours,numEchange)
178 self.LineEditEnCours.setFocus(True)
179 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
181 def echange(self,num1,num2):
182 # on donne le focus au a celui ou on a bouge
183 # par convention le 2
184 nomLineEdit=self.nomLine+str(num1)
186 courant=getattr(self,nomLineEdit)
187 valeurAGarder=courant.text()
188 nomLineEdit2=self.nomLine+str(num2)
190 courant2=getattr(self,nomLineEdit2)
191 courant.setText(courant2.text())
192 courant2.setText(valeurAGarder)
193 self.changeValeur(changeDePlace=False)
194 self.NumLineEditEnCours=num2
195 self.LineEditEnCours=courant2
196 self.LineEditEnCours.setFocus(True)
198 def moinsPushed(self):
199 # on supprime le dernier
200 if self.NumLineEditEnCours == 0 : return
201 if self.NumLineEditEnCours==self.indexDernierLabel :
202 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
203 courant=getattr(self,nomLineEdit)
206 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
208 nomLineEdit=self.nomLine+str(aRemonter)
209 courant=getattr(self,nomLineEdit)
210 valeurARemonter=courant.getValeur()
211 nomLineEdit=self.nomLine+str(i)
212 courant=getattr(self,nomLineEdit)
213 if valeurARemonter != None : courant.setValeur(valeurARemonter)
214 else : courant.clean()
215 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
216 courant=getattr(self,nomLineEdit)
218 self.changeValeur(changeDePlace=False,oblige=True)
221 def plusPushed(self):
222 if self.indexDernierLabel == self.monSimpDef.max:
223 if len(self.listeValeursCourantes) < self.monSimpDef.max : self.chercheLigneVide()
224 else : self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
227 self.descendLesLignes()
229 def chercheLigneVide(self):
230 for i in range(self.indexDernierLabel) :
231 nomLineEdit=self.nomLine+str(i+1)
232 courant=getattr(self,nomLineEdit)
233 valeur=courant.getValeur()
234 if valeur=="" : courant.setFocus(7);return
237 def descendLesLignes(self):
238 if self.NumLineEditEnCours==self.indexDernierLabel : return
239 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
240 courant=getattr(self,nomLineEdit)
241 valeurADescendre=courant.getValeur()
243 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
245 nomLineEdit=self.nomLine+str(aDescendre)
246 courant=getattr(self,nomLineEdit)
247 valeurAGarder=courant.getValeur()
248 courant.setValeur(valeurADescendre)
249 valeurADescendre=valeurAGarder
250 self.changeValeur(changeDePlace=False)
251 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
253 def voisListePushed(self):
255 for v in self.node.item.GetListeValeurs():
256 texteValeurs+=str(v)+", "
257 entete="Valeurs pour "+self.nom
258 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
262 def selectInFile(self):
263 init=str( self.editor.CONFIGURATION.savedir)
264 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
265 tr("Fichier de donnees"),
267 tr('Tous les Fichiers (*)',))
269 if fn == None : return
271 ulfile = os.path.abspath(six.text_type(fn))
272 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
274 from .monSelectVal import MonSelectVal
275 MonSelectVal(file=fn,parent=self).show()
277 def noircirResultatFiltre(self):
278 filtre=str(self.LEFiltre.text())
279 for cb in self.listeCbRouge:
280 palette = QPalette(Qt.red)
281 palette.setColor(QPalette.WindowText,Qt.black)
282 cb.setPalette(palette)
285 self.LEFiltre.setText("")
286 self.listeCbRouge = []
290 class GerePlie(object):
293 def gereIconePlier(self):
294 if not(hasattr(self,'BFermeListe')) : return
295 self.editor.listeDesListesOuvertes.add(self.node.item)
296 repIcon=self.node.editor.appliEficas.repIcon
297 if not (self.editor.afficheListesPliees):
298 fichier=os.path.join(repIcon, 'empty.png')
299 icon = QIcon(fichier)
300 self.BFermeListe.setIcon(icon)
302 fichier=os.path.join(repIcon, 'minusnode.png')
303 icon = QIcon(fichier)
304 self.BFermeListe.setIcon(icon)
305 self.BFermeListe.clicked.connect( self.selectWidgetPlie)
307 def selectWidgetPlie(self):
308 self.editor.listeDesListesOuvertes.remove(self.node.item)
309 self.reaffichePourDeplier()