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
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 from monViewTexte import ViewText
31 # ---------------------- #
32 class LECustom(QLineEdit):
33 # ---------------------- #
34 def __init__(self,parent,parentQt,i):
38 QLineEdit.__init__(self,parent)
39 self.parentQt=parentQt
41 self.dansUnTuple=False
43 def focusInEvent(self,event):
44 #print "dans focusInEvent de LECustom"
45 self.parentQt.LineEditEnCours=self
46 self.parentQt.NumLineEditEnCours=self.num
47 self.setStyleSheet("border: 2px solid gray")
48 QLineEdit.focusInEvent(self,event)
50 def focusOutEvent(self,event):
51 #print "dans focusOutEvent de LECustom"
52 self.setStyleSheet("border: 0px")
53 if self.dansUnTuple : self.setStyleSheet("background:rgb(235,235,235); border: 0px;")
54 elif self.num % 2 == 1 : self.setStyleSheet("background:rgb(210,210,210)")
55 else : self.setStyleSheet("background:rgb(235,235,235)")
56 QLineEdit.focusOutEvent(self,event)
64 def setValeur(self,valeur):
67 # --------------------------- #
68 class LECustomTuple(LECustom):
69 # --------------------------- #
70 def __init__(self,parent):
71 # index sera mis a jour par TupleCustom
72 parentQt=parent.parent().parent().parent()
73 LECustom. __init__(self,parent,parentQt,0)
75 # ---------------------------- #
76 class MonLabelListeClic(QLabel):
77 # ---------------------------- #
78 def __init__(self,parent):
79 QLabel.__init__(self,parent)
82 def event(self,event) :
83 if event.type() == QEvent.MouseButtonRelease:
84 self.texte=self.text()
85 self.parent.traiteClicSurLabelListe(self.texte)
86 return QLabel.event(self,event)
96 self.connecterSignaux()
98 def connecterSignaux(self):
99 self.connect(self.RBHaut,SIGNAL("clicked()"),self.hautPushed)
100 self.connect(self.RBBas,SIGNAL("clicked()"),self.basPushed)
101 self.connect(self.RBMoins,SIGNAL("clicked()"),self.moinsPushed)
102 self.connect(self.RBPlus,SIGNAL("clicked()"),self.plusPushed)
103 self.connect(self.RBVoisListe,SIGNAL("clicked()"),self.voisListePushed)
105 def hautPushed(self):
106 if self.NumLineEditEnCours == 1 : return
107 else : numEchange=self.NumLineEditEnCours-1
108 self.echange(self.NumLineEditEnCours,numEchange)
109 self.LineEditEnCours.setFocus(True)
110 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
114 if self.NumLineEditEnCours == self.indexDernierLabel : return
115 else : numEchange=self.NumLineEditEnCours+1
116 self.echange(self.NumLineEditEnCours,numEchange)
117 self.LineEditEnCours.setFocus(True)
118 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
120 def echange(self,num1,num2):
121 # on donne le focus au a celui ou on a bouge
122 # par convention le 2
123 nomLineEdit=self.nomLine+str(num1)
125 courant=getattr(self,nomLineEdit)
126 valeurAGarder=courant.text()
127 nomLineEdit2=self.nomLine+str(num2)
129 courant2=getattr(self,nomLineEdit2)
130 courant.setText(courant2.text())
131 courant2.setText(valeurAGarder)
132 self.changeValeur(changeDePlace=False)
133 self.NumLineEditEnCours=num2
134 self.LineEditEnCours=courant2
135 self.LineEditEnCours.setFocus(True)
137 def moinsPushed(self):
138 # on supprime le dernier
139 if self.NumLineEditEnCours==self.indexDernierLabel :
140 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
141 courant=getattr(self,nomLineEdit)
144 for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
146 nomLineEdit=self.nomLine+str(aRemonter)
147 courant=getattr(self,nomLineEdit)
148 valeurARemonter=courant.getValeur()
149 nomLineEdit=self.nomLine+str(i)
150 courant=getattr(self,nomLineEdit)
151 if valeurARemonter != None : courant.setValeur(valeurARemonter)
152 else : courant.clean()
153 nomLineEdit=self.nomLine+str(self.indexDernierLabel)
154 courant=getattr(self,nomLineEdit)
156 self.changeValeur(changeDePlace=False,oblige=True)
159 def plusPushed(self):
160 if self.indexDernierLabel == self.monSimpDef.max:
161 self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
164 self.descendLesLignes()
166 def descendLesLignes(self):
167 if self.NumLineEditEnCours==self.indexDernierLabel : return
168 nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
169 courant=getattr(self,nomLineEdit)
170 valeurADescendre=courant.getValeur()
172 for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
174 nomLineEdit=self.nomLine+str(aDescendre)
175 courant=getattr(self,nomLineEdit)
176 valeurAGarder=courant.getValeur()
177 courant.setValeur(valeurADescendre)
178 valeurADescendre=valeurAGarder
179 self.changeValeur(changeDePlace=False)
180 self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
182 def voisListePushed(self):
184 for v in self.node.item.GetListeValeurs():
185 texteValeurs+=str(v)+", "
186 entete="Valeurs pour "+self.nom
187 f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
191 def selectInFile(self):
192 init=QString( self.editor.CONFIGURATION.savedir)
193 fn = QFileDialog.getOpenFileName(self.node.appliEficas,
194 tr("Fichier de donnees"),
196 tr('Tous les Fichiers (*)',))
197 if fn == None : return
199 ulfile = os.path.abspath(unicode(fn))
200 self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
202 from monSelectVal import MonSelectVal
203 MonSelectVal(file=fn,parent=self).show()
210 def gereIconePlier(self):
211 if not(hasattr(self,'BFermeListe')) : return
212 repIcon=self.node.editor.appliEficas.repIcon
213 if not (self.editor.afficheListesPliees):
214 fichier=os.path.join(repIcon, 'empty.png')
215 icon = QIcon(fichier)
216 self.BFermeListe.setIcon(icon)
218 fichier=os.path.join(repIcon, 'minusnode.png')
219 icon = QIcon(fichier)
220 self.BFermeListe.setIcon(icon)
221 self.connect(self.BFermeListe,SIGNAL("clicked()"), self.selectWidgetPlie)
223 def selectWidgetPlie(self):
224 self.editor.listeDesListesOuvertes.remove(self.node.item)
225 self.reaffichePourDeplier()