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.indexDernierLabel == 0 : return
210 if self.NumLineEditEnCours==self.indexDernierLabel :
211 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
212 courant=getattr(self,nomLineEdit)
215 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
217 nomLineEdit=self.nomLine+str(aRemonter)
218 courant=getattr(self,nomLineEdit)
219 valeurARemonter=courant.getValeur()
220 nomLineEdit=self.nomLine+str(i)
221 courant=getattr(self,nomLineEdit)
222 if valeurARemonter != None : courant.setValeur(valeurARemonter)
223 else : courant.clean()
224 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
225 courant=getattr(self,nomLineEdit)
227 self.changeValeur(changeDePlace=False,oblige=True)
230 def plusPushed(self):
231 if self.indexDernierLabel == self.monSimpDef.max:
232 if len(self.listeValeursCourantes) < self.monSimpDef.max : self.chercheLigneVide()
233 else : self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
236 self.descendLesLignes()
238 def chercheLigneVide(self):
239 for i in range(self.indexDernierLabel) :
240 nomLineEdit=self.nomLine+str(i+1)
241 courant=getattr(self,nomLineEdit)
242 valeur=courant.getValeur()
243 if valeur=="" : courant.setFocus(7);return
246 def descendLesLignes(self):
247 if self.NumLineEditEnCours==self.indexDernierLabel : return
248 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
249 courant=getattr(self,nomLineEdit)
250 valeurADescendre=courant.getValeur()
252 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
254 nomLineEdit=self.nomLine+str(aDescendre)
255 courant=getattr(self,nomLineEdit)
256 valeurAGarder=courant.getValeur()
257 courant.setValeur(valeurADescendre)
258 valeurADescendre=valeurAGarder
259 self.changeValeur(changeDePlace=False)
260 if hasattr (self, 'LineEditEnCours') :self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
262 def voisListePushed(self):
264 for v in self.node.item.GetListeValeurs():
265 texteValeurs+=str(v)+", "
266 entete="Valeurs pour "+self.nom
267 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
271 def selectInFile(self):
272 init=str( self.editor.CONFIGURATION.savedir)
273 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
274 tr("Fichier de donnees"),
276 tr('Tous les Fichiers (*)',))
278 if fn == None : return
280 ulfile = os.path.abspath(six.text_type(fn))
281 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
283 from .monSelectVal import MonSelectVal
284 MonSelectVal(file=fn,parent=self).show()
286 def noircirResultatFiltre(self):
287 filtre=str(self.LEFiltre.text())
288 for cb in self.listeCbRouge:
289 palette = QPalette(Qt.red)
290 palette.setColor(QPalette.WindowText,Qt.black)
291 cb.setPalette(palette)
294 self.LEFiltre.setText("")
295 self.listeCbRouge = []
299 class GerePlie(object):
302 def gereIconePlier(self):
303 if not(hasattr(self,'BFermeListe')) : return
304 self.editor.listeDesListesOuvertes.add(self.node.item)
305 repIcon=self.node.editor.appliEficas.repIcon
306 if not (self.editor.afficheListesPliees):
307 fichier=os.path.join(repIcon, 'empty.png')
308 icon = QIcon(fichier)
309 self.BFermeListe.setIcon(icon)
311 fichier=os.path.join(repIcon, 'minusnode.png')
312 icon = QIcon(fichier)
313 self.BFermeListe.setIcon(icon)
314 self.BFermeListe.clicked.connect( self.selectWidgetPlie)
316 def selectWidgetPlie(self):
317 self.editor.listeDesListesOuvertes.remove(self.node.item)
318 self.reaffichePourDeplier()