Salome HOME
sauvegarde
[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
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 LECustom
34 from monLabelClic           import MonLabelClic
35
36
37 class MonWidgetPlusieursIntoOrdonne (Ui_WidgetPlusieursIntoOrdonne, Feuille,GereListe):
38
39   def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
40         #print "MonWidgetPlusieursInto", nom, self
41         self.nomLine="LEResultat"
42         Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
43         GereListe.__init__(self)
44         self.parentQt.commandesLayout.insertWidget(-1,self)
45         self.maCommande.listeAffichageWidget.append(self.lineEditVal1)
46         self.prepareListeResultat()
47         self.vScrollBarRE = self.scrollAreaRE.verticalScrollBar()
48        
49
50   def setValeurs(self):
51        listeValeursCourantes=self.node.item.GetListeValeurs()
52        if hasattr(self.node.item.definition.validators,'set_MCSimp'):
53             obj=self.node.item.getObject()
54             self.node.item.definition.validators.set_MCSimp(obj)
55             if self.node.item.isvalid() == 0 :
56                liste=[]
57                for item in listeValeursCourantes:
58                    if self.node.item.definition.validators.verif_item(item)==1:
59                       liste.append(item)
60                self.listeAAfficher=self.node.item.get_liste_possible(liste)
61             else: 
62                self.listeAAfficher=self.node.item.get_liste_possible([])
63        else :
64                self.listeAAfficher=self.monSimpDef.into
65        if len(self.listeAAfficher)*20 > 400 : self.setMinimumHeight(400)
66        else : self.setMinimumHeight(len(self.listeAAfficher)*30)
67        self.adjustSize()
68        self.vScrollBar = self.scrollArea.verticalScrollBar()
69        self.politique=PolitiquePlusieurs(self.node,self.editor)
70        for i in range(1,len(self.listeAAfficher)+1):
71            self.ajoutLE(i)
72        for i in range(len(self.listeAAfficher)):
73            nomLE="lineEditVal"+str(i+1)
74            courant=getattr(self,nomLE)
75            courant.setText(str(self.listeAAfficher[i]))
76        self.vScrollBar.triggerAction(QScrollBar.SliderToMinimum)
77        
78   def prepareListeResultat(self):
79        listeValeursCourantes=self.node.item.GetListeValeurs()
80        if self.monSimpDef.max == "**" : aConstruire=7
81        else                           : aConstruire=self.monSimpDef.max
82        if len(listeValeursCourantes) > aConstruire : aConstruire=len(listeValeursCourantes)
83        for i in range(1,aConstruire+1):
84            self.ajoutLEResultat(i)
85        self.indexDernierLabel=aConstruire
86        index=1
87        for val in listeValeursCourantes :
88           nomLE="LEResultat"+str(index)
89           courant=getattr(self,nomLE)
90           courant.setText(str(val))
91           courant.setReadOnly(True)
92           index=index+1
93
94
95   def ajoutLineEdit(self):
96       print "kljlkj"
97
98   def ajoutLEResultat (self,index,valeur=None):
99       nomLE="LEResultat"+str(index)
100       if hasattr(self,nomLE) : return
101       nouveauLE = LECustom(self.scrollAreaRE,self,index)
102       nouveauLE.setFrame(False)
103       self.CBChoisis.addWidget(nouveauLE)
104       nouveauLE.setText("")
105       nouveauLE.setReadOnly(True)
106       if index % 2 == 1 : nouveauLE.setStyleSheet("background:rgb(210,210,210)")
107       else :              nouveauLE.setStyleSheet("background:rgb(240,240,240)")
108       self.vScrollBar.triggerAction(QScrollBar.SliderToMaximum)
109       setattr(self,nomLE,nouveauLE)
110       self.estVisibleRE=nouveauLE
111       if valeur != None : 
112          nouveauLE.setText(valeur)
113       
114   def ajoutLE(self,index,valeur=None):
115       #print "ajoutLE ", index
116       nomLE="lineEditVal"+str(index)
117       if hasattr(self,nomLE) : return
118       nouveauLE = MonLabelClic(self)
119       self.CBLayout.addWidget(nouveauLE)
120       nouveauLE.setFrameShape(QFrame.NoFrame)
121       qApp.processEvents()
122       nouveauLE.setText("")
123       if index % 2 == 1 : nouveauLE.setStyleSheet("background:rgb(210,210,210)")
124       else :              nouveauLE.setStyleSheet("background:rgb(240,240,240)")
125       self.vScrollBar.triggerAction(QScrollBar.SliderToMaximum)
126       nouveauLE.setFocus()
127       setattr(self,nomLE,nouveauLE)
128       
129
130   def finCommentaire(self):
131         commentaire=""
132         mc = self.node.item.get_definition()
133         d_aides = { 'TXM' : 'chaines de caracteres',
134                   'R'   : 'reels',
135                   'I'   : 'entiers',
136                   'C'   : 'complexes'}
137         type = mc.type[0]
138         if not d_aides.has_key(type) :
139            if mc.min == mc.max:
140                commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")
141            else :
142                commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")
143         else :
144            if mc.min == mc.max:
145                commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])
146            else :
147                commentaire=tr("Entrez entre ")+str(mc.min)+(" et  ")+str(mc.max) +" " +tr(d_aides[type])
148         aideval=self.node.item.aide()
149         com=commentaire + "   " + QString.toUtf8(QString(aideval))
150         return str(com)
151
152
153   def traiteClicSurLabel(self,valeur):
154         if valeur == None : return
155         liste,validite=SaisieValeur.TraiteLEValeur(self,str(valeur))
156         if validite == 0 : return
157         if liste ==[]    : return
158         listeVal=[]
159
160         listeValeursCourantes=self.node.item.GetListeValeurs()
161         min,max = self.node.item.GetMinMax()
162         if len(listeValeursCourantes) +1 > max : 
163            self.editor.affiche_infos(tr("Nombre maximal de valeurs : ") + str(max),Qt.red)
164            return
165         else :
166            self.editor.affiche_infos(tr(""))
167
168         affiche=False
169         for i in range(1,self.indexDernierLabel+1):
170            nomLE="LEResultat"+str(i)
171            courant=getattr(self,nomLE)
172            if str(courant.text())==str("") : 
173               courant.setText(valeur)
174               courant.setReadOnly(True)
175               affiche=True
176               self.estVisibleRE=courant
177               QTimer.singleShot(1, self.rendVisibleLigneRE)
178               break
179           
180         if affiche == False:
181            self.indexDernierLabel = self.indexDernierLabel+1
182            self.ajoutLEResultat (self.indexDernierLabel,str(valeur))
183            self.vScrollBarRE.triggerAction(QScrollBar.SliderToMaximum)
184            QTimer.singleShot(1, self.rendVisibleLigneRE)
185         self.changeValeur()
186
187   def changeValeur(self,changeDePlace=False,oblige=False):
188 #PN les 2 arg sont pour que la signature de ma fonction soit identique a monWidgetPlusieursBase
189         listeVal=[]
190         for i in range(1,self.indexDernierLabel+1):
191            nomLE="LEResultat"+str(i)
192            courant=getattr(self,nomLE)
193            valeur=courant.text()
194            if str(valeur)=="" : continue
195            liste,validite=SaisieValeur.TraiteLEValeur(self,str(valeur))
196            listeVal.append(str(valeur))
197
198         validite,comm,comm2,listeRetour=self.politique.AjoutValeurs(listeVal,-1,[])
199
200         listeValeursCourantes=self.node.item.GetListeValeurs()
201         min,max = self.node.item.GetMinMax()
202         if len(listeValeursCourantes) < min : 
203            self.editor.affiche_infos(tr("Nombre minimal de valeurs : ") + str(min),Qt.red)
204         else :
205            self.editor.affiche_infos("")
206     
207         if validite :
208            self.node.item.set_valeur(listeRetour)
209         else :
210            commentaire=comm+" "+comm2
211            self.editor.affiche_infos(commentaire,Qt.red)
212         self.setValide()
213 #
214   def rendVisibleLigneRE(self):
215       qApp.processEvents()
216       self.estVisibleRE.setFocus()
217       self.scrollArea.ensureWidgetVisible(self.estVisibleRE,0,0)
218 #