Salome HOME
fin portage python 3
[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 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 six.moves import range
30 from PyQt5.QtCore import Qt
31
32 # Modules Eficas
33 from Extensions.i18n import tr
34
35 from .feuille               import Feuille
36 from .politiquesValidation  import PolitiqueUnique
37 from .qtSaisie              import SaisieValeur
38
39
40 class MonWidgetSimpTuple(Feuille):
41
42   def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
43         Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
44         self.politique=PolitiqueUnique(self.node,self.editor)
45         self.parentQt.commandesLayout.insertWidget(-1,self)
46         self.setFocusPolicy(Qt.StrongFocus)
47
48   def setValeurs(self):
49        valeur=self.node.item.get_valeur()
50        for i in range(self.nbValeurs) :
51            nomLineEdit="lineEditVal"+str(i+1)
52            courant=getattr(self,nomLineEdit)
53            if valeur !=None: courant.setText(str(valeur[i]))
54            setattr(self,nomLineEdit,courant)
55            courant.returnPressed.connect(self.valeursPressed)
56
57   def valeursPressed(self):
58       aLeFocus=self.focusWidget()
59       self.editor.affiche_infos("")
60       texteValeur=""
61       for i in range(self.nbValeurs) :
62           nomLineEdit="lineEditVal"+str(i+1)
63           courant=getattr(self,nomLineEdit)
64           if courant.text()=="" or courant.text()==None :
65              courant.setFocus(True)
66              return 
67           s=str(courant.text())
68           if hasattr(self.objSimp.definition.validators, 'typeDesTuples'):
69            if self.objSimp.definition.validators.typeDesTuples[i] == "R" :
70              if (s.find('.')== -1 and s.find('e')== -1 and s.find('E')==-1) : 
71                  s=s+'.0'
72                  courant.setText(s)
73            if self.objSimp.definition.validators.typeDesTuples[i] == "TXM" :
74              if s[0]!='"' and s[0] != "'": 
75                 if s[-1]=="'": s="'"+s
76                 else :         s='"'+s
77              if s[-1]!='"' and s[-1] != "'": 
78                 if s[0]=="'": s=s+"'"
79                 else :        s=s+'"'
80              courant.setText(s)
81           texteValeur+=str(courant.text())
82           if i+1 != self.nbValeurs : texteValeur+=','
83       validite,commentaire=self.politique.RecordValeur(texteValeur)
84       if not validite:self.editor.affiche_infos(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)
99           
100