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.setStyleSheet("border: 2px solid gray")
54 QLineEdit.focusInEvent(self,event)
56 def focusOutEvent(self,event):
57 #print "dans focusOutEvent de LECustom"
58 self.setStyleSheet("border: 0px")
59 if self.dansUnTuple : self.setStyleSheet("background:rgb(235,235,235); border: 0px;")
60 elif self.num % 2 == 1 : self.setStyleSheet("background:rgb(210,210,210)")
61 else : self.setStyleSheet("background:rgb(235,235,235)")
62 QLineEdit.focusOutEvent(self,event)
70 def setValeur(self,valeur):
73 # --------------------------- #
74 class LECustomTuple(LECustom):
75 # --------------------------- #
76 def __init__(self,parent):
77 # index sera mis a jour par TupleCustom
78 parentQt=parent.parent().parent().parent()
79 LECustom. __init__(self,parent,parentQt,0)
81 # ---------------------------- #
82 class MonLabelListeClic(QLabel):
83 # ---------------------------- #
84 def __init__(self,parent):
85 QLabel.__init__(self,parent)
88 def event(self,event) :
89 if event.type() == QEvent.MouseButtonRelease:
90 self.texte=self.text()
91 self.parent.traiteClicSurLabelListe(self.texte)
92 return QLabel.event(self,event)
102 if monEnvQT5 :self.connecterSignaux()
103 else : self.connecterSignauxQT4()
105 def connecterSignauxQT4(self):
106 if hasattr(self,'RBHaut'):
107 self.connect(self.RBHaut,SIGNAL("clicked()"),self.hautPushed)
108 self.connect(self.RBBas,SIGNAL("clicked()"),self.basPushed)
109 self.connect(self.RBMoins,SIGNAL("clicked()"),self.moinsPushed)
110 self.connect(self.RBPlus,SIGNAL("clicked()"),self.plusPushed)
111 self.connect(self.RBVoisListe,SIGNAL("clicked()"),self.voisListePushed)
112 if hasattr(self,'PBAlpha'):
113 self.connect(self.PBAlpha,SIGNAL("clicked()"),self.alphaPushed)
114 self.connect(self.PBCata,SIGNAL("clicked()"),self.cataPushed)
115 self.connect(self.PBFind,SIGNAL("clicked()"),self.findPushed)
116 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.LEFiltreReturnPressed)
118 def connecterSignaux(self):
119 if hasattr(self,'RBHaut'):
120 self.RBHaut.clicked.connect(self.hautPushed)
121 self.RBBas.clicked.connect(self.basPushed)
122 self.RBMoins.clicked.connect(self.moinsPushed)
123 self.RBPlus.clicked.connect(self.plusPushed)
124 self.RBVoisListe.clicked.connect(self.voisListePushed)
125 if hasattr(self,'PBAlpha'):
126 self.PBCata.clicked.connect(self.cataPushed)
127 self.PBAlpha.clicked.connect(self.alphaPushed)
128 self.PBFind.clicked.connect(self.findPushed)
129 self.LEFiltre.returnPressed.connect(self.LEFiltreReturnPressed)
131 def filtreListe(self):
134 if self.filtre != "" :
135 for i in self.listeAAfficher :
136 if i.find(self.filtre) == 0 :l.append(i)
137 self.listeAAfficher=l
138 if self.alpha : self.listeAAfficher.sort()
140 def LEFiltreReturnPressed(self):
141 self.filtre= self.LEFiltre.text()
142 self.prepareListeResultatFiltre()
144 def findPushed(self):
145 self.filtre= self.LEFiltre.text()
146 self.prepareListeResultatFiltre()
148 def alphaPushed(self):
149 print "alphaPushed" ,self.alpha
150 if self.alpha == 1 : return
152 self.prepareListeResultat()
154 def cataPushed(self):
155 if self.alpha == 0 : return
157 self.prepareListeResultat()
159 def hautPushed(self):
160 if self.NumLineEditEnCours == 1 : return
161 else : numEchange=self.NumLineEditEnCours-1
162 self.echange(self.NumLineEditEnCours,numEchange)
163 self.LineEditEnCours.setFocus(True)
164 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
168 if self.NumLineEditEnCours == self.indexDernierLabel : return
169 else : numEchange=self.NumLineEditEnCours+1
170 self.echange(self.NumLineEditEnCours,numEchange)
171 self.LineEditEnCours.setFocus(True)
172 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
174 def echange(self,num1,num2):
175 # on donne le focus au a celui ou on a bouge
176 # par convention le 2
177 nomLineEdit=self.nomLine+str(num1)
179 courant=getattr(self,nomLineEdit)
180 valeurAGarder=courant.text()
181 nomLineEdit2=self.nomLine+str(num2)
183 courant2=getattr(self,nomLineEdit2)
184 courant.setText(courant2.text())
185 courant2.setText(valeurAGarder)
186 self.changeValeur(changeDePlace=False)
187 self.NumLineEditEnCours=num2
188 self.LineEditEnCours=courant2
189 self.LineEditEnCours.setFocus(True)
191 def moinsPushed(self):
192 # on supprime le dernier
193 if self.NumLineEditEnCours==self.indexDernierLabel :
194 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
195 courant=getattr(self,nomLineEdit)
198 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
200 nomLineEdit=self.nomLine+str(aRemonter)
201 courant=getattr(self,nomLineEdit)
202 valeurARemonter=courant.getValeur()
203 nomLineEdit=self.nomLine+str(i)
204 courant=getattr(self,nomLineEdit)
205 if valeurARemonter != None : courant.setValeur(valeurARemonter)
206 else : courant.clean()
207 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
208 courant=getattr(self,nomLineEdit)
210 self.changeValeur(changeDePlace=False,oblige=True)
213 def plusPushed(self):
214 if self.indexDernierLabel == self.monSimpDef.max:
215 if len(self.listeValeursCourantes) < self.monSimpDef.max : self.chercheLigneVide()
216 else : self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
219 self.descendLesLignes()
221 def chercheLigneVide(self):
222 for i in range(self.indexDernierLabel) :
223 nomLineEdit=self.nomLine+str(i+1)
224 courant=getattr(self,nomLineEdit)
225 valeur=courant.getValeur()
226 if valeur=="" : courant.setFocus(7);return
229 def descendLesLignes(self):
230 if self.NumLineEditEnCours==self.indexDernierLabel : return
231 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
232 courant=getattr(self,nomLineEdit)
233 valeurADescendre=courant.getValeur()
235 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
237 nomLineEdit=self.nomLine+str(aDescendre)
238 courant=getattr(self,nomLineEdit)
239 valeurAGarder=courant.getValeur()
240 courant.setValeur(valeurADescendre)
241 valeurADescendre=valeurAGarder
242 self.changeValeur(changeDePlace=False)
243 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
245 def voisListePushed(self):
247 for v in self.node.item.GetListeValeurs():
248 texteValeurs+=str(v)+", "
249 entete="Valeurs pour "+self.nom
250 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
254 def selectInFile(self):
255 init=QString( self.editor.CONFIGURATION.savedir)
256 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
257 tr("Fichier de donnees"),
259 tr('Tous les Fichiers (*)',))
260 if fn == None : return
262 ulfile = os.path.abspath(unicode(fn))
263 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
265 from monSelectVal import MonSelectVal
266 MonSelectVal(file=fn,parent=self).show()
268 def noircirResultatFiltre(self):
269 filtre=str(self.LEFiltre.text())
270 for cb in self.listeCbRouge:
271 palette = QPalette(Qt.red)
272 palette.setColor(QPalette.WindowText,Qt.black)
273 cb.setPalette(palette)
276 self.LEFiltre.setText("")
277 self.listeCbRouge = []
284 def gereIconePlier(self):
285 if not(hasattr(self,'BFermeListe')) : return
286 repIcon=self.node.editor.appliEficas.repIcon
287 if not (self.editor.afficheListesPliees):
288 fichier=os.path.join(repIcon, 'empty.png')
289 icon = QIcon(fichier)
290 self.BFermeListe.setIcon(icon)
292 fichier=os.path.join(repIcon, 'minusnode.png')
293 icon = QIcon(fichier)
294 self.BFermeListe.setIcon(icon)
295 if monEnvQT5 : self.BFermeListe.clicked.connect( self.selectWidgetPlie)
296 else : self.connect(self.BFermeListe,SIGNAL("clicked()"), self.selectWidgetPlie)
298 def selectWidgetPlie(self):
299 self.editor.listeDesListesOuvertes.remove(self.node.item)
300 self.reaffichePourDeplier()