Salome HOME
518b24e6d8368d936f143fe360c6560afdb6079f
[tools/eficas.git] / InterfaceQT4 / gereListe.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Modules Python
21 import string,types,os
22 import traceback
23
24 from PyQt4 import *
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28 from monViewTexte   import ViewText
29
30
31 # ---------------------- #
32 class LECustom(QLineEdit):
33 # ---------------------- #
34  def __init__(self,parent,parentQt,i):
35         """
36         Constructor
37         """
38         QLineEdit.__init__(self,parent)
39         self.parentQt=parentQt
40         self.num=i
41         self.dansUnTuple=False
42
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)
49
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)
57
58  def clean(self):
59      self.setText("")
60
61  def getValeur(self):
62      return self.text()
63
64  def setValeur(self,valeur):
65      self.setText(valeur)
66
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)
74
75 # ---------------------------- #
76 class MonLabelListeClic(QLabel):
77 # ---------------------------- #
78      def __init__(self,parent):
79         QLabel.__init__(self,parent)
80         self.parent=parent
81
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)
87
88
89
90
91 # ------------- #
92 class GereListe:
93 # ------------- #
94
95    def __init__(self):
96        self.connecterSignaux()
97
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)
104
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)
111
112
113    def basPushed(self):
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)
119
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)
124        #print nomLineEdit
125        courant=getattr(self,nomLineEdit)
126        valeurAGarder=courant.text()
127        nomLineEdit2=self.nomLine+str(num2)
128        #print nomLineEdit2
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)
136
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)
142           courant.clean()
143        else :
144          for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
145              aRemonter=i+1
146              nomLineEdit=self.nomLine+str(aRemonter)
147              print nomLineEdit
148              courant=getattr(self,nomLineEdit)
149              valeurARemonter=courant.getValeur()
150              print valeurARemonter
151              nomLineEdit=self.nomLine+str(i)
152              print nomLineEdit
153              courant=getattr(self,nomLineEdit)
154              if valeurARemonter != None : courant.setValeur(valeurARemonter)
155              else : courant.clean()
156          nomLineEdit=self.nomLine+str(self.indexDernierLabel)
157          courant=getattr(self,nomLineEdit)
158          courant.clean()
159        self.changeValeur(changeDePlace=False,oblige=True)
160        self.setValide()
161
162    def plusPushed(self):
163        if self.indexDernierLabel == self.monSimpDef.max:
164           self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint',Qt.red)
165           return
166        self.ajoutLineEdit()
167        self.descendLesLignes()
168
169    def descendLesLignes(self):
170        if self.NumLineEditEnCours==self.indexDernierLabel : return
171        nomLineEdit=self.nomLine+str(self.NumLineEditEnCours+1)
172        courant=getattr(self,nomLineEdit)
173        valeurADescendre=courant.getValeur()
174        courant.clean()
175        for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
176              aDescendre=i+1
177              nomLineEdit=self.nomLine+str(aDescendre)
178              courant=getattr(self,nomLineEdit)
179              valeurAGarder=courant.getValeur()
180              courant.setValeur(valeurADescendre)
181              valeurADescendre=valeurAGarder
182        self.changeValeur(changeDePlace=False)
183        self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
184
185    def voisListePushed(self):
186        print "voisListePushed"
187        texteValeurs=""
188        for v in self.node.item.GetListeValeurs():
189           texteValeurs+=str(v)+", "
190        entete="Valeurs pour "+self.nom
191        f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
192        f.show()
193
194
195    def selectInFile(self):
196        print "selectInFile"
197        init=QString( self.editor.CONFIGURATION.savedir)
198        fn = QFileDialog.getOpenFileName(self.node.appliEficas,
199                                          tr("Fichier de donnees"),
200                                          init,
201                                          tr('Tous les  Fichiers (*)',))
202        if fn == None : return
203        if fn == "" : return
204        ulfile = os.path.abspath(unicode(fn))
205        self.editor.CONFIGURATION.savedir=os.path.split(ulfile)[0]
206
207        from monSelectVal import MonSelectVal
208        MonSelectVal(file=fn,parent=self).show()
209
210