Salome HOME
3c13529305514054930638117c947bd1478329f2
[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 class LECustom(QLineEdit):
32 # ---------------------- #
33  def __init__(self,parent,parentQt,i):
34         """
35         Constructor
36         """
37         QMainWindow.__init__(self,parent)
38         self.parentQt=parentQt
39         self.num=i
40
41  def focusInEvent(self,event):
42      self.parentQt.LineEditEnCours=self
43      self.parentQt.NumLineEditEnCours=self.num
44
45
46
47
48 # ------------- #
49 class GereListe:
50 # ------------- #
51
52    def __init__(self):
53        self.connecterSignaux()
54
55    def connecterSignaux(self):
56        self.connect(self.RBHaut,SIGNAL("clicked()"),self.hautPushed)
57        self.connect(self.RBBas,SIGNAL("clicked()"),self.basPushed)
58        self.connect(self.RBMoins,SIGNAL("clicked()"),self.moinsPushed)
59        self.connect(self.RBPlus,SIGNAL("clicked()"),self.plusPushed)
60        self.connect(self.RBVoisListe,SIGNAL("clicked()"),self.voisListePushed)
61        self.connect(self.RBSalome,SIGNAL("clicked()"),self.salomePushed)
62        self.connect(self.RBSalomeVue,SIGNAL("clicked()"),self.salomeVuePushed)
63
64    def hautPushed(self):
65        if self.NumLineEditEnCours == 1 : return
66        else : numEchange=self.NumLineEditEnCours-1
67        self.echange(self.NumLineEditEnCours,numEchange)
68        self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
69
70
71    def basPushed(self):
72        if self.NumLineEditEnCours == self.indexDernierLabel : return
73        else : numEchange=self.NumLineEditEnCours+1
74        self.echange(self.NumLineEditEnCours,numEchange)
75        self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
76
77    def echange(self,num1,num2):
78        # on donne le focus au a celui ou on a bouge
79        # par convention le 2
80        nomLineEdit="lineEditVal"+str(num1)
81        #print nomLineEdit
82        courant=getattr(self,nomLineEdit)
83        valeurAGarder=courant.text()
84        nomLineEdit2="lineEditVal"+str(num2)
85        #print nomLineEdit2
86        courant2=getattr(self,nomLineEdit2)
87        courant.setText(courant2.text())
88        courant2.setText(valeurAGarder)
89        self.changeValeur(changeDePlace=False)
90        self.NumLineEditEnCours=num2
91        self.LineEditEnCours=courant2
92
93    def moinsPushed(self):
94        if self.indexDernierLabel < self.monSimpDef.min:
95           self.editor.affiche_infos('nb min de valeurs : '+str(self.monSimpDef.min)+' atteint')
96           return
97        # on supprime le dernier
98        if self.NumLineEditEnCours==self.indexDernierLabel : 
99           self.setText("")
100        else :
101          for i in range (self.NumLineEditEnCours, self.indexDernierLabel):
102              aRemonter=i+1
103              nomLineEdit="lineEditVal"+str(aRemonter)
104              courant=getattr(self,nomLineEdit)
105              valeurARemonter=courant.text()
106              nomLineEdit="lineEditVal"+str(i)
107              courant=getattr(self,nomLineEdit)
108              courant.setText(valeurARemonter)
109          nomLineEdit="lineEditVal"+str(self.indexDernierLabel)
110          courant=getattr(self,nomLineEdit)
111          courant.setText("")
112        self.changeValeur(changeDePlace=False)
113
114    def plusPushed(self):
115        if self.indexDernierLabel == self.monSimpDef.max:
116           self.editor.affiche_infos('nb max de valeurs : '+str(self.monSimpDef.max)+' atteint')
117           return
118        self.ajoutLineEdit()
119        if self.NumLineEditEnCours==self.indexDernierLabel : return
120        nomLineEdit="lineEditVal"+str(self.NumLineEditEnCours+1)
121        courant=getattr(self,nomLineEdit)
122        valeurADescendre=courant.text()
123        courant.setText("")
124        for i in range (self.NumLineEditEnCours+1, self.indexDernierLabel):
125              aDescendre=i+1
126              nomLineEdit="lineEditVal"+str(aDescendre)
127              courant=getattr(self,nomLineEdit)
128              valeurAGarder=courant.text()
129              courant.setText(valeurADescendre)
130              valeurADescendre=valeurAGarder
131        self.changeValeur(changeDePlace=False)
132        self.scrollArea.ensureWidgetVisible(self.LineEditEnCours)
133
134    def voisListePushed(self):
135        print "voisListePushed"
136        texteValeurs=""
137        for v in self.node.item.GetListeValeurs():
138           texteValeurs+=str(v)+", "
139        entete="Valeurs pour "+self.nom
140        f=ViewText(self,self.editor,entete,texteValeurs[0:-2])
141        f.show()
142
143    def salomePushed(self):
144        print "salomePushed"
145
146    def salomeVuePushed(self):
147        print "salomeVuePushed"
148