Salome HOME
sauve du 9 mai
[tools/eficas.git] / InterfaceQT4 / monWidgetSimpTuple.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 from determine import monEnvQT5
24 if monEnvQT5:
25     from PyQt5.QtCore import Qt
26 else :
27     from PyQt4.QtGui  import *
28     from PyQt4.QtCore import *
29
30 # Modules Eficas
31 from Extensions.i18n import tr
32
33 from feuille               import Feuille
34 from politiquesValidation  import PolitiqueUnique
35 from qtSaisie              import SaisieValeur
36
37
38 class MonWidgetSimpTuple(Feuille):
39
40   def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
41         Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
42         self.politique=PolitiqueUnique(self.node,self.editor)
43         self.parentQt.commandesLayout.insertWidget(-1,self)
44         self.setFocusPolicy(Qt.StrongFocus)
45
46   def setValeurs(self):
47        valeur=self.node.item.get_valeur()
48        for i in range(self.nbValeurs) :
49            nomLineEdit="lineEditVal"+str(i+1)
50            courant=getattr(self,nomLineEdit)
51            if valeur !=None: courant.setText(str(valeur[i]))
52            setattr(self,nomLineEdit,courant)
53            if monEnvQT5: courant.returnPressed.connect(self.valeursPressed)
54            else : self.connect(courant,SIGNAL("returnPressed()"),self.valeursPressed)
55
56   def valeursPressed(self):
57       aLeFocus=self.focusWidget()
58       self.editor.affiche_infos("")
59       texteValeur=""
60       for i in range(self.nbValeurs) :
61           nomLineEdit="lineEditVal"+str(i+1)
62           courant=getattr(self,nomLineEdit)
63           if courant.text()=="" or courant.text()==None :
64              courant.setFocus(True)
65              return 
66           s=str(courant.text())
67           if self.objSimp.definition.validators.typeDesTuples[i] == "R" :
68              if (s.find('.')== -1 and s.find('e')== -1 and s.find('E')==-1) : 
69                  s=s+'.0'
70                  courant.setText(s)
71           if self.objSimp.definition.validators.typeDesTuples[i] == "TXM" :
72              if s[0]!='"' and s[0] != "'": 
73                 if s[-1]=="'": s="'"+s
74                 else :         s='"'+s
75              if s[-1]!='"' and s[-1] != "'": 
76                 if s[0]=="'": s=s+"'"
77                 else :        s=s+'"'
78              courant.setText(s)
79           texteValeur+=str(courant.text())
80           if i+1 != self.nbValeurs : texteValeur+=','
81       validite,commentaire=self.politique.RecordValeur(texteValeur)
82       if not validite:self.editor.affiche_infos(commentaire+" "+str(self.objSimp.definition.validators.typeDesTuples),Qt.red)
83
84       # Passage au champ suivant
85       nom=aLeFocus.objectName()[11:]
86       i=nom.toInt()[0]+1
87       if i == self.nbValeurs +1 : i=1
88       nomLineEdit="lineEditVal"+str(i)
89       courant=getattr(self,nomLineEdit)
90       courant.setFocus(True)
91           
92