Salome HOME
7bd475a6e565f168431ab2850a8694b9135fe6e7
[tools/eficas.git] / InterfaceQT4 / monWidgetPlusieursIntoOrdonne.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,sys
22
23 # Modules Eficas
24 from PyQt4.QtGui import *
25 from PyQt4.QtCore import *
26 from Extensions.i18n import tr
27
28 from feuille                import Feuille
29 from desWidgetPlusieursIntoOrdonne import Ui_WidgetPlusieursIntoOrdonne 
30 from politiquesValidation   import PolitiquePlusieurs
31 from qtSaisie               import SaisieValeur
32 from gereListe              import GereListe
33 from gereListe              import GerePlie
34 from gereListe              import LECustom
35 from gereListe              import MonLabelListeClic
36
37
38
39 class MonWidgetPlusieursIntoOrdonne (Ui_WidgetPlusieursIntoOrdonne, Feuille,GereListe,GerePlie):
40
41   def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
42         #print "MonWidgetPlusieursInto", nom, self
43         self.nomLine="LEResultat"
44         self.listeLE=[]
45         self.ouAjouter=0
46         self.NumLineEditEnCours=0
47         Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
48         GereListe.__init__(self)
49         self.finCommentaireListe()
50         self.gereIconePlier()
51         try :
52           self.maCommande.listeAffichageWidget.append(self.lineEditVal1)
53         except :
54           # cas ou on ne peut rien ajouter
55           pass 
56         self.prepareListeResultat()
57         self.adjustSize()
58         if sys.platform[0:5]!="linux":
59           repIcon=self.node.editor.appliEficas.repIcon
60           fichier=os.path.join(repIcon, 'arrow_up.png')
61           icon = QIcon(fichier)
62           self.RBHaut.setIcon(icon)
63           self.RBHaut.setIconSize(QSize(32, 32))
64           fichier2=os.path.join(repIcon, 'arrow_down.png')
65           icon2 = QIcon(fichier2)
66           self.RBBas.setIcon(icon2)
67         self.parentQt.commandesLayout.insertWidget(-1,self)
68
69        
70   def prepareListeResultat(self):
71        print "prepareListeResultat"
72        for i in self.listeLE: i.close()
73        self.listeLE=[]
74        self.vScrollBar = self.scrollArea.verticalScrollBar()
75        listeValeursCourantes=self.node.item.GetListeValeurs()
76        if hasattr(self.node.item.definition.validators,'set_MCSimp'):
77             obj=self.node.item.getObject()
78             self.node.item.definition.validators.set_MCSimp(obj)
79             if self.node.item.isvalid() == 0 :
80                liste=[]
81                for item in listeValeursCourantes:
82                    if self.node.item.definition.validators.verif_item(item)==1: liste.append(item)
83                self.listeAAfficher=self.node.item.get_liste_possible(liste)
84             else: 
85                self.listeAAfficher=self.node.item.get_liste_possible([])
86        else :
87             self.listeAAfficher=self.node.item.get_liste_possible(listeValeursCourantes)
88
89        if self.listeAAfficher==[] : 
90           self.ajoutLE(0)
91           return
92        if len(self.listeAAfficher)*20 > 400 : self.setMinimumHeight(400)
93        else : self.setMinimumHeight(len(self.listeAAfficher)*30)
94
95        self.politique=PolitiquePlusieurs(self.node,self.editor)
96        for i in range(1,len(self.listeAAfficher)+1): self.ajoutLE(i)
97        for i in range(len(self.listeAAfficher)):
98            nomLE="lineEditVal"+str(i+1)
99            courant=getattr(self,nomLE)
100            courant.setText(str(self.listeAAfficher[i]))
101        self.vScrollBar.triggerAction(QScrollBar.SliderToMinimum)
102        
103       
104   def setValeurs(self):
105        listeValeursCourantes=self.node.item.GetListeValeurs()
106        if self.monSimpDef.max == "**" : aConstruire=7
107        else                           : aConstruire=self.monSimpDef.max
108        if len(listeValeursCourantes) > aConstruire : aConstruire=len(listeValeursCourantes)
109        for i in range(1,aConstruire+1): self.ajoutLEResultat(i)
110        self.indexDernierLabel=aConstruire
111        index=1
112        for val in listeValeursCourantes :
113           nomLE="LEResultat"+str(index)
114           courant=getattr(self,nomLE)
115           courant.setText(str(val))
116           courant.setReadOnly(True)
117           index=index+1
118        self.prepareListeResultat()
119
120   def moinsPushed(self):
121       self.ouAjouter=self.ouAjouter-1
122       GereListe.moinsPushed(self)
123       self.setValeurs()
124
125
126   def ajoutLEResultat (self,index,valeur=None):
127       nomLE="LEResultat"+str(index)
128       if hasattr(self,nomLE) : return
129       nouveauLE = LECustom(self.scrollAreaRE,self,index)
130       nouveauLE.setFrame(False)
131       self.CBChoisis.insertWidget(self.ouAjouter,nouveauLE)
132       self.ouAjouter=self.ouAjouter+1
133       nouveauLE.setText("")
134       nouveauLE.setReadOnly(True)
135       if index % 2 == 1 : nouveauLE.setStyleSheet("background:rgb(210,210,210)")
136       else :              nouveauLE.setStyleSheet("background:rgb(240,240,240)")
137       self.vScrollBarRE = self.scrollAreaRE.verticalScrollBar()
138       self.vScrollBarRE.triggerAction(QScrollBar.SliderToMaximum)
139       setattr(self,nomLE,nouveauLE)
140       self.estVisibleRE=nouveauLE
141       if valeur != None : 
142          nouveauLE.setText(valeur)
143       
144   def ajoutLE(self,index,valeur=None):
145       nomLE="lineEditVal"+str(index)
146       nouveauLE = MonLabelListeClic(self)
147       #self.CBLayout.addWidget(nouveauLE)
148       self.CBLayout.insertWidget(index -1,nouveauLE)
149       self.listeLE.append(nouveauLE)
150       nouveauLE.setFrameShape(QFrame.NoFrame)
151       qApp.processEvents()
152       nouveauLE.setText("")
153       if index % 2 == 1 : nouveauLE.setStyleSheet("background:rgb(210,210,210)")
154       else :              nouveauLE.setStyleSheet("background:rgb(240,240,240)")
155       self.vScrollBar.triggerAction(QScrollBar.SliderToMaximum)
156       nouveauLE.setFocus()
157       setattr(self,nomLE,nouveauLE)
158       
159   def ajoutLineEdit(self):
160       self.ajoutLEResultat (self.indexDernierLabel)
161
162
163   def traiteClicSurLabelListe(self,valeur):
164         if valeur == None : return
165         liste,validite=SaisieValeur.TraiteLEValeur(self,str(valeur))
166         if validite == 0 : return
167         if liste ==[]    : return
168         listeVal=[]
169
170         listeValeursCourantes=self.node.item.GetListeValeurs()
171         min,max = self.node.item.GetMinMax()
172         if len(listeValeursCourantes) +1 > max : 
173            self.editor.affiche_infos(tr("Nombre maximal de valeurs : ") + str(max),Qt.red)
174            return
175         else :
176            self.editor.affiche_infos(tr(""))
177
178         affiche=False
179         for i in range(1,self.indexDernierLabel+1):
180            nomLE="LEResultat"+str(i)
181            courant=getattr(self,nomLE)
182            if str(courant.text())==str("") : 
183               courant.setText(valeur)
184               courant.setReadOnly(True)
185               affiche=True
186               self.estVisibleRE=courant
187               QTimer.singleShot(1, self.rendVisibleLigneRE)
188               break
189           
190         if affiche == False:
191            self.indexDernierLabel = self.indexDernierLabel+1
192            self.ajoutLEResultat (self.indexDernierLabel,str(valeur))
193            self.vScrollBarRE.triggerAction(QScrollBar.SliderToMaximum)
194            QTimer.singleShot(1, self.rendVisibleLigneRE)
195         self.changeValeur()
196         self.setValeurs()
197
198   def changeValeur(self,changeDePlace=False,oblige=False):
199 #PN les 2 arg sont pour que la signature de ma fonction soit identique a monWidgetPlusieursBase
200         listeVal=[]
201         for i in range(1,self.indexDernierLabel+1):
202            nomLE="LEResultat"+str(i)
203            courant=getattr(self,nomLE)
204            valeur=courant.text()
205            if str(valeur)=="" : continue
206            liste,validite=SaisieValeur.TraiteLEValeur(self,str(valeur))
207            listeVal.append(str(valeur))
208
209         validite,comm,comm2,listeRetour=self.politique.AjoutValeurs(listeVal,-1,[])
210         
211
212         listeValeursCourantes=self.node.item.GetListeValeurs()
213         min,max = self.node.item.GetMinMax()
214         if len(listeValeursCourantes) < min : 
215            self.editor.affiche_infos(tr("Nombre minimal de valeurs : ") + str(min),Qt.red)
216         else :
217            self.editor.affiche_infos("")
218     
219         if len(listeRetour) == 0 :
220            self.node.item.set_valeur(None)
221         elif validite :
222            self.node.item.set_valeur(listeRetour)
223         else :
224            commentaire=comm+" "+comm2
225            self.editor.affiche_infos(commentaire,Qt.red)
226         self.setValide()
227 #
228   def rendVisibleLigneRE(self):
229       qApp.processEvents()
230       self.estVisibleRE.setFocus()
231       self.scrollArea.ensureWidgetVisible(self.estVisibleRE,0,0)
232 #
233
234