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
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)
112 def connecterSignaux(self):
113 self.RBHaut.clicked.connect(self.hautPushed)
114 self.RBBas.clicked.connect(self.basPushed)
115 self.RBMoins.clicked.connect(self.moinsPushed)
116 self.RBPlus.clicked.connect(self.plusPushed)
117 self.RBVoisListe.clicked.connect(self.voisListePushed)
119 def hautPushed(self):
120 if self.NumLineEditEnCours == 1 : return
121 else : numEchange=self.NumLineEditEnCours-1
122 self.echange(self.NumLineEditEnCours,numEchange)
123 self.LineEditEnCours.setFocus(True)
124 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
128 if self.NumLineEditEnCours == self.indexDernierLabel : return
129 else : numEchange=self.NumLineEditEnCours+1
130 self.echange(self.NumLineEditEnCours,numEchange)
131 self.LineEditEnCours.setFocus(True)
132 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
134 def echange(self,num1,num2):
135 # on donne le focus au a celui ou on a bouge
136 # par convention le 2
137 nomLineEdit=self.nomLine+str(num1)
139 courant=getattr(self,nomLineEdit)
140 valeurAGarder=courant.text()
141 nomLineEdit2=self.nomLine+str(num2)
143 courant2=getattr(self,nomLineEdit2)
144 courant.setText(courant2.text())
145 courant2.setText(valeurAGarder)
146 self.changeValeur(changeDePlace=False)
147 self.NumLineEditEnCours=num2
148 self.LineEditEnCours=courant2
149 self.LineEditEnCours.setFocus(True)
151 def moinsPushed(self):
152 # on supprime le dernier
153 if self.NumLineEditEnCours==self.indexDernierLabel :
154 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
155 courant=getattr(self,nomLineEdit)
158 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
160 nomLineEdit=self.nomLine+str(aRemonter)
161 courant=getattr(self,nomLineEdit)
162 valeurARemonter=courant.getValeur()
163 nomLineEdit=self.nomLine+str(i)
164 courant=getattr(self,nomLineEdit)
165 if valeurARemonter != None : courant.setValeur(valeurARemonter)
166 else : courant.clean()
167 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
168 courant=getattr(self,nomLineEdit)
170 self.changeValeur(changeDePlace=False,oblige=True)
173 def plusPushed(self):
174 if self.indexDernierLabel == self.monSimpDef.max:
175 self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
178 self.descendLesLignes()
180 def descendLesLignes(self):
181 if self.NumLineEditEnCours==self.indexDernierLabel : return
182 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
183 courant=getattr(self,nomLineEdit)
184 valeurADescendre=courant.getValeur()
186 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
188 nomLineEdit=self.nomLine+str(aDescendre)
189 courant=getattr(self,nomLineEdit)
190 valeurAGarder=courant.getValeur()
191 courant.setValeur(valeurADescendre)
192 valeurADescendre=valeurAGarder
193 self.changeValeur(changeDePlace=False)
194 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
196 def voisListePushed(self):
198 for v in self.node.item.GetListeValeurs():
199 texteValeurs+=str(v)+", "
200 entete="Valeurs pour "+self.nom
201 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
205 def selectInFile(self):
206 init=QString( self.editor.CONFIGURATION.savedir)
207 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
208 tr("Fichier de donnees"),
210 tr('Tous les Fichiers (*)',))
211 if fn == None : return
213 ulfile = os.path.abspath(unicode(fn))
214 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
216 from monSelectVal import MonSelectVal
217 MonSelectVal(file=fn,parent=self).show()
224 def gereIconePlier(self):
225 if not(hasattr(self,'BFermeListe')) : return
226 repIcon=self.node.editor.appliEficas.repIcon
227 if not (self.editor.afficheListesPliees):
228 fichier=os.path.join(repIcon, 'empty.png')
229 icon = QIcon(fichier)
230 self.BFermeListe.setIcon(icon)
232 fichier=os.path.join(repIcon, 'minusnode.png')
233 icon = QIcon(fichier)
234 self.BFermeListe.setIcon(icon)
235 if monEnvQT5 : self.BFermeListe.clicked.connect( self.selectWidgetPlie)
236 else : self.connect(self.BFermeListe,SIGNAL("clicked()"), self.selectWidgetPlie)
238 def selectWidgetPlie(self):
239 self.editor.listeDesListesOuvertes.remove(self.node.item)
240 self.reaffichePourDeplier()