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
21 import string,types,os
24 from determine import monEnvQT5
26 from PyQt5.QtWidgets import QLineEdit, QLabel
27 from PyQt5.QtCore import QEvent, Qt
28 from PyQt5.QtGui import QIcon, QPalette
30 from PyQt4.QtGui import *
31 from PyQt4.QtCore import *
33 from Extensions.i18n import tr
34 from monViewTexte import ViewText
37 # ---------------------- #
38 class LECustom(QLineEdit):
39 # ---------------------- #
40 def __init__(self,parent,parentQt,i):
44 QLineEdit.__init__(self,parent)
45 self.parentQt=parentQt
47 self.dansUnTuple=False
49 def focusInEvent(self,event):
50 #print "dans focusInEvent de LECustom"
51 self.parentQt.LineEditEnCours=self
52 self.parentQt.NumLineEditEnCours=self.num
53 self.parentQt.textSelected=self.text()
54 self.setStyleSheet("border: 2px solid gray")
55 QLineEdit.focusInEvent(self,event)
57 def focusOutEvent(self,event):
58 #print "dans focusOutEvent de LECustom"
59 self.setStyleSheet("border: 0px")
60 if self.dansUnTuple : self.setStyleSheet("background:rgb(235,235,235); border: 0px;")
61 elif self.num % 2 == 1 : self.setStyleSheet("background:rgb(210,210,210)")
62 else : self.setStyleSheet("background:rgb(235,235,235)")
63 QLineEdit.focusOutEvent(self,event)
71 def setValeur(self,valeur):
76 # --------------------------- #
77 class LECustomTuple(LECustom):
78 # --------------------------- #
79 def __init__(self,parent):
80 # index sera mis a jour par TupleCustom
81 parentQt=parent.parent().parent().parent()
82 LECustom. __init__(self,parent,parentQt,0)
84 # ---------------------------- #
85 class MonLabelListeClic(QLabel):
86 # ---------------------------- #
87 def __init__(self,parent):
88 QLabel.__init__(self,parent)
91 def event(self,event) :
92 if event.type() == QEvent.MouseButtonRelease:
93 self.texte=self.text()
94 self.parent.traiteClicSurLabelListe(self.texte)
95 return QLabel.event(self,event)
105 if monEnvQT5 :self.connecterSignaux()
106 else : self.connecterSignauxQT4()
108 def connecterSignauxQT4(self):
109 if hasattr(self,'RBHaut'):
110 self.connect(self.RBHaut,SIGNAL("clicked()"),self.hautPushed)
111 self.connect(self.RBBas,SIGNAL("clicked()"),self.basPushed)
112 self.connect(self.RBMoins,SIGNAL("clicked()"),self.moinsPushed)
113 self.connect(self.RBPlus,SIGNAL("clicked()"),self.plusPushed)
114 self.connect(self.RBVoisListe,SIGNAL("clicked()"),self.voisListePushed)
115 if hasattr(self,'PBAlpha'):
116 self.connect(self.PBAlpha,SIGNAL("clicked()"),self.alphaPushed)
117 self.connect(self.PBCata,SIGNAL("clicked()"),self.cataPushed)
118 self.connect(self.PBFind,SIGNAL("clicked()"),self.findPushed)
119 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.LEFiltreReturnPressed)
121 def connecterSignaux(self):
122 if hasattr(self,'RBHaut'):
123 self.RBHaut.clicked.connect(self.hautPushed)
124 self.RBBas.clicked.connect(self.basPushed)
125 self.RBMoins.clicked.connect(self.moinsPushed)
126 self.RBPlus.clicked.connect(self.plusPushed)
127 self.RBVoisListe.clicked.connect(self.voisListePushed)
128 if hasattr(self,'PBAlpha'):
129 self.PBCata.clicked.connect(self.cataPushed)
130 self.PBAlpha.clicked.connect(self.alphaPushed)
131 self.PBFind.clicked.connect(self.findPushed)
132 self.LEFiltre.returnPressed.connect(self.LEFiltreReturnPressed)
134 def filtreListe(self):
136 if self.filtre != "" :
137 for i in self.listeAAfficher :
138 if i.find(self.filtre) == 0 :l.append(i)
139 self.listeAAfficher=l
140 if self.alpha : self.listeAAfficher.sort()
142 def LEFiltreReturnPressed(self):
143 self.filtre= self.LEFiltre.text()
144 self.prepareListeResultatFiltre()
146 def findPushed(self):
147 self.filtre= self.LEFiltre.text()
148 self.prepareListeResultatFiltre()
150 def alphaPushed(self):
151 #print "alphaPushed" ,self.alpha
152 if self.alpha == 1 : return
154 self.prepareListeResultat()
156 def cataPushed(self):
157 if self.alpha == 0 : return
159 self.prepareListeResultat()
161 def hautPushed(self):
162 if self.NumLineEditEnCours == 1 : return
163 else : numEchange=self.NumLineEditEnCours-1
164 self.echange(self.NumLineEditEnCours,numEchange)
165 self.LineEditEnCours.setFocus(True)
166 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
170 if self.NumLineEditEnCours == self.indexDernierLabel : return
171 else : numEchange=self.NumLineEditEnCours+1
172 self.echange(self.NumLineEditEnCours,numEchange)
173 self.LineEditEnCours.setFocus(True)
174 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
176 def echange(self,num1,num2):
177 # on donne le focus au a celui ou on a bouge
178 # par convention le 2
179 nomLineEdit=self.nomLine+str(num1)
181 courant=getattr(self,nomLineEdit)
182 valeurAGarder=courant.text()
183 nomLineEdit2=self.nomLine+str(num2)
185 courant2=getattr(self,nomLineEdit2)
186 courant.setText(courant2.text())
187 courant2.setText(valeurAGarder)
188 self.changeValeur(changeDePlace=False)
189 self.NumLineEditEnCours=num2
190 self.LineEditEnCours=courant2
191 self.LineEditEnCours.setFocus(True)
193 def moinsPushed(self):
194 # on supprime le dernier
195 if self.NumLineEditEnCours==self.indexDernierLabel :
196 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
197 courant=getattr(self,nomLineEdit)
200 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
202 nomLineEdit=self.nomLine+str(aRemonter)
203 courant=getattr(self,nomLineEdit)
204 valeurARemonter=courant.getValeur()
205 nomLineEdit=self.nomLine+str(i)
206 courant=getattr(self,nomLineEdit)
207 if valeurARemonter != None : courant.setValeur(valeurARemonter)
208 else : courant.clean()
209 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
210 courant=getattr(self,nomLineEdit)
212 self.changeValeur(changeDePlace=False,oblige=True)
215 def plusPushed(self):
216 if self.indexDernierLabel == self.monSimpDef.max:
217 if len(self.listeValeursCourantes) < self.monSimpDef.max : self.chercheLigneVide()
218 else : self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
221 self.descendLesLignes()
223 def chercheLigneVide(self):
224 for i in range(self.indexDernierLabel) :
225 nomLineEdit=self.nomLine+str(i+1)
226 courant=getattr(self,nomLineEdit)
227 valeur=courant.getValeur()
228 if valeur=="" : courant.setFocus(7);return
231 def descendLesLignes(self):
232 if self.NumLineEditEnCours==self.indexDernierLabel : return
233 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
234 courant=getattr(self,nomLineEdit)
235 valeurADescendre=courant.getValeur()
237 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
239 nomLineEdit=self.nomLine+str(aDescendre)
240 courant=getattr(self,nomLineEdit)
241 valeurAGarder=courant.getValeur()
242 courant.setValeur(valeurADescendre)
243 valeurADescendre=valeurAGarder
244 self.changeValeur(changeDePlace=False)
245 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
247 def voisListePushed(self):
249 for v in self.node.item.GetListeValeurs():
250 texteValeurs+=str(v)+", "
251 entete="Valeurs pour "+self.nom
252 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
256 def selectInFile(self):
257 init=QString( self.editor.CONFIGURATION.savedir)
258 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
259 tr("Fichier de donnees"),
261 tr('Tous les Fichiers (*)',))
262 if fn == None : return
264 ulfile = os.path.abspath(unicode(fn))
265 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
267 from monSelectVal import MonSelectVal
268 MonSelectVal(file=fn,parent=self).show()
270 def noircirResultatFiltre(self):
271 filtre=str(self.LEFiltre.text())
272 for cb in self.listeCbRouge:
273 palette = QPalette(Qt.red)
274 palette.setColor(QPalette.WindowText,Qt.black)
275 cb.setPalette(palette)
278 self.LEFiltre.setText("")
279 self.listeCbRouge = []
286 def gereIconePlier(self):
287 if not(hasattr(self,'BFermeListe')) : return
288 self.editor.listeDesListesOuvertes.add(self.node.item)
289 repIcon=self.node.editor.appliEficas.repIcon
290 if not (self.editor.afficheListesPliees):
291 fichier=os.path.join(repIcon, 'empty.png')
292 icon = QIcon(fichier)
293 self.BFermeListe.setIcon(icon)
295 fichier=os.path.join(repIcon, 'minusnode.png')
296 icon = QIcon(fichier)
297 self.BFermeListe.setIcon(icon)
298 if monEnvQT5 : self.BFermeListe.clicked.connect( self.selectWidgetPlie)
299 else : self.connect(self.BFermeListe,SIGNAL("clicked()"), self.selectWidgetPlie)
301 def selectWidgetPlie(self):
302 self.editor.listeDesListesOuvertes.remove(self.node.item)
303 self.reaffichePourDeplier()