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
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 self.connect(self.RBHaut,SIGNAL("clicked()"),self.hautPushed)
107 self.connect(self.RBBas,SIGNAL("clicked()"),self.basPushed)
108 self.connect(self.RBMoins,SIGNAL("clicked()"),self.moinsPushed)
109 self.connect(self.RBPlus,SIGNAL("clicked()"),self.plusPushed)
110 self.connect(self.RBVoisListe,SIGNAL("clicked()"),self.voisListePushed)
111 if hasattr(self,'PBAlpha'):
112 self.connect(self.PBAlpha,SIGNAL("clicked()"),self.alphaPushed)
113 self.connect(self.PBCata,SIGNAL("clicked()"),self.cataPushed)
114 self.connect(self.PBFind,SIGNAL("clicked()"),self.findPushed)
115 self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.LEFiltreReturnPressed)
117 def connecterSignaux(self):
118 self.RBHaut.clicked.connect(self.hautPushed)
119 self.RBBas.clicked.connect(self.basPushed)
120 self.RBMoins.clicked.connect(self.moinsPushed)
121 self.RBPlus.clicked.connect(self.plusPushed)
122 self.RBVoisListe.clicked.connect(self.voisListePushed)
123 if hasattr(self,'PBAlpha'):
124 self.PBCata.clicked.connect(self.cataPushed)
125 self.PBAlpha.clicked.connect(self.alphaPushed)
126 self.PBFind.clicked.connect(self.findPushed)
127 self.LEFiltre.returnPressed.connect(self.LEFiltreReturnPressed)
129 def filtreListe(self):
132 if self.filtre != "" :
133 for i in self.listeAAfficher :
134 if i.find(self.filtre) == 0 :l.append(i)
135 self.listeAAfficher=l
136 if self.alpha : self.listeAAfficher.sort()
138 def LEFiltreReturnPressed(self):
139 self.filtre= self.LEFiltre.text()
140 self.prepareListeResultat()
142 def findPushed(self):
143 self.filtre= self.LEFiltre.text()
144 self.prepareListeResultat()
146 def alphaPushed(self):
147 print "alphaPushed" ,self.alpha
148 if self.alpha == 1 : return
149 print "lllllllmmmmmmmmmmmmmm"
151 self.prepareListeResultat()
153 def cataPushed(self):
154 if self.alpha == 0 : return
156 self.prepareListeResultat()
158 def hautPushed(self):
159 if self.NumLineEditEnCours == 1 : return
160 else : numEchange=self.NumLineEditEnCours-1
161 self.echange(self.NumLineEditEnCours,numEchange)
162 self.LineEditEnCours.setFocus(True)
163 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
167 if self.NumLineEditEnCours == self.indexDernierLabel : return
168 else : numEchange=self.NumLineEditEnCours+1
169 self.echange(self.NumLineEditEnCours,numEchange)
170 self.LineEditEnCours.setFocus(True)
171 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
173 def echange(self,num1,num2):
174 # on donne le focus au a celui ou on a bouge
175 # par convention le 2
176 nomLineEdit=self.nomLine+str(num1)
178 courant=getattr(self,nomLineEdit)
179 valeurAGarder=courant.text()
180 nomLineEdit2=self.nomLine+str(num2)
182 courant2=getattr(self,nomLineEdit2)
183 courant.setText(courant2.text())
184 courant2.setText(valeurAGarder)
185 self.changeValeur(changeDePlace=False)
186 self.NumLineEditEnCours=num2
187 self.LineEditEnCours=courant2
188 self.LineEditEnCours.setFocus(True)
190 def moinsPushed(self):
191 # on supprime le dernier
192 if self.NumLineEditEnCours==self.indexDernierLabel :
193 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
194 courant=getattr(self,nomLineEdit)
197 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
199 nomLineEdit=self.nomLine+str(aRemonter)
200 courant=getattr(self,nomLineEdit)
201 valeurARemonter=courant.getValeur()
202 nomLineEdit=self.nomLine+str(i)
203 courant=getattr(self,nomLineEdit)
204 if valeurARemonter != None : courant.setValeur(valeurARemonter)
205 else : courant.clean()
206 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
207 courant=getattr(self,nomLineEdit)
209 self.changeValeur(changeDePlace=False,oblige=True)
212 def plusPushed(self):
213 if self.indexDernierLabel == self.monSimpDef.max:
214 if len(self.listeValeursCourantes) < self.monSimpDef.max : self.chercheLigneVide()
215 else : self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
218 self.descendLesLignes()
220 def chercheLigneVide(self):
221 for i in range(self.indexDernierLabel) :
222 nomLineEdit=self.nomLine+str(i+1)
223 courant=getattr(self,nomLineEdit)
224 valeur=courant.getValeur()
225 if valeur=="" : courant.setFocus(7);return
228 def descendLesLignes(self):
229 if self.NumLineEditEnCours==self.indexDernierLabel : return
230 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
231 courant=getattr(self,nomLineEdit)
232 valeurADescendre=courant.getValeur()
234 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
236 nomLineEdit=self.nomLine+str(aDescendre)
237 courant=getattr(self,nomLineEdit)
238 valeurAGarder=courant.getValeur()
239 courant.setValeur(valeurADescendre)
240 valeurADescendre=valeurAGarder
241 self.changeValeur(changeDePlace=False)
242 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
244 def voisListePushed(self):
246 for v in self.node.item.GetListeValeurs():
247 texteValeurs+=str(v)+", "
248 entete="Valeurs pour "+self.nom
249 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
253 def selectInFile(self):
254 init=QString( self.editor.CONFIGURATION.savedir)
255 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
256 tr("Fichier de donnees"),
258 tr('Tous les Fichiers (*)',))
259 if fn == None : return
261 ulfile = os.path.abspath(unicode(fn))
262 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
264 from monSelectVal import MonSelectVal
265 MonSelectVal(file=fn,parent=self).show()
272 def gereIconePlier(self):
273 if not(hasattr(self,'BFermeListe')) : return
274 repIcon=self.node.editor.appliEficas.repIcon
275 if not (self.editor.afficheListesPliees):
276 fichier=os.path.join(repIcon, 'empty.png')
277 icon = QIcon(fichier)
278 self.BFermeListe.setIcon(icon)
280 fichier=os.path.join(repIcon, 'minusnode.png')
281 icon = QIcon(fichier)
282 self.BFermeListe.setIcon(icon)
283 if monEnvQT5 : self.BFermeListe.clicked.connect( self.selectWidgetPlie)
284 else : self.connect(self.BFermeListe,SIGNAL("clicked()"), self.selectWidgetPlie)
286 def selectWidgetPlie(self):
287 self.editor.listeDesListesOuvertes.remove(self.node.item)
288 self.reaffichePourDeplier()