Salome HOME
Update version
[tools/eficas.git] / InterfaceQT4 / monWidgetSimpTuple.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   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 from __future__ import absolute_import
22 try :
23     from builtins import str
24     from builtins import range
25 except : pass
26
27 import types,os
28
29 from PyQt5.QtCore import Qt
30
31 # Modules Eficas
32 from Extensions.i18n import tr
33
34 from InterfaceQT4.feuille               import Feuille
35 from InterfaceQT4.politiquesValidation  import PolitiqueUnique
36 from InterfaceQT4.qtSaisie              import SaisieValeur
37
38
39 class MonWidgetSimpTuple(Feuille):
40
41     def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
42         Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
43         self.politique=PolitiqueUnique(self.node,self.editor)
44         self.parentQt.commandesLayout.insertWidget(-1,self)
45         self.setFocusPolicy(Qt.StrongFocus)
46
47     def setValeurs(self):
48         valeur=self.node.item.getValeur()
49         for i in range(self.nbValeurs) :
50             nomLineEdit="lineEditVal"+str(i+1)
51             courant=getattr(self,nomLineEdit)
52             if valeur !=None: courant.setText(str(valeur[i]))
53             setattr(self,nomLineEdit,courant)
54             courant.returnPressed.connect(self.valeursPressed)
55
56     def valeursPressed(self):
57         aLeFocus=self.focusWidget()
58         self.editor.afficheInfos("")
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 hasattr(self.objSimp.definition.validators, 'typeDesTuples'):
68                 if self.objSimp.definition.validators.typeDesTuples[i] == "R" :
69                     if (s.find('.')== -1 and s.find('e')== -1 and s.find('E')==-1) :
70                         s=s+'.0'
71                         courant.setText(s)
72                 if self.objSimp.definition.validators.typeDesTuples[i] == "TXM" :
73                     if s[0]!='"' and s[0] != "'":
74                         if s[-1]=="'": s="'"+s
75                         else :         s='"'+s
76                     if s[-1]!='"' and s[-1] != "'":
77                         if s[0]=="'": s=s+"'"
78                         else :        s=s+'"'
79                     courant.setText(s)
80             texteValeur+=str(courant.text())
81             #print (texteValeur)
82             if i+1 != self.nbValeurs : texteValeur+=','
83         validite,commentaire=self.politique.recordValeur(texteValeur)
84         if not validite:self.editor.afficheInfos(commentaire+" "+str(self.objSimp.definition.validators.typeDesTuples),Qt.red)
85
86         # Passage au champ suivant
87         nom=aLeFocus.objectName()[11:]
88         try :
89             i=int(nom)+1
90         except :
91             try :
92                 i=i+1
93             except :
94                 return
95         if i == self.nbValeurs +1 : i=1
96         nomLineEdit="lineEditVal"+str(i)
97         courant=getattr(self,nomLineEdit)
98         courant.setFocus(True)