Salome HOME
Pour V1 Carmel
[tools/eficas.git] / InterfaceQT4 / qtSaisie.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 from PyQt4 import *
23 from PyQt4.QtGui import *
24 from PyQt4.QtCore import *
25 from Extensions.i18n import tr
26
27
28 # Import des panels
29
30 class SaisieValeur:
31   """
32   Classe contenant les méthodes communes aux  panels
33   permettant de choisir des valeurs 
34   """
35   def __init__(self):
36        pass
37
38
39   def LEValeurPressed(self,valeur=None):
40          if valeur == None :
41             nouvelleValeur=str(self.lineEditVal.text())
42          else :
43             if hasattr(self,"lineEditVal"):self.lineEditVal.setText(QString(valeur.nom))
44             nouvelleValeur=valeur
45          validite,commentaire=self.politique.RecordValeur(nouvelleValeur)
46          if commentaire != "" :
47             #PNPNPNP Il faut trouver une solution pour les 2 cas 
48             #   self.editor.affiche_infos(commentaire)
49             #self.Commentaire.setText(QString(commentaire))
50             if validite :
51                 self.editor.affiche_infos(commentaire)
52             else :
53                 self.editor.affiche_infos(commentaire,Qt.red)
54          self.setValide()
55
56
57   #def TraiteLEValeurTuple(self,valeurBrute=None) :
58   #      listeValeurs=[]
59   #      if valeurBrute== None :valeurBrute=str(self.LEValeur.text())
60   #      listeValeursSplit=valeurBrute.split(',')
61   #      for val in listeValeursSplit :
62   #          try :
63   #             valeur=eval(val,{})        
64   #          except :
65   #             valeur=val
66   #          listeValeurs.append(valeur)
67   #      return listeValeurs
68
69   def TraiteLEValeur(self,valeurTraitee=None) :
70         # lit la chaine entree dans le line edit
71         # et la tranforme en chaine de valeurs
72         # a traiter. renvoie eventuellement des complexes
73         listeValeurs=[]
74         if valeurTraitee == None :
75            valeurBrute=str(self.LEValeur.text())
76         else :
77            valeurBrute=valeurTraitee
78         if valeurBrute == str("") : return listeValeurs,1
79
80         try :
81             valeur=eval(valeurBrute,{})        
82         except :
83             valeur=valeurBrute
84
85         if type(valeur)  in (types.ListType,types.TupleType) :
86            if self.node.item.wait_complex() :
87               indice = 0
88               while (indice < len(valeur)):
89                  v=valeur[indice]
90
91                  if (v== 'RI' or v == 'MP'):
92                     try :
93                        t=tuple([v,valeur[indice+1],valeur[indice+2]])
94                        listeValeurs.append(t)
95                        indice=indice+3
96                     except :
97                        commentaire = tr("Veuillez entrer le complexe sous forme aster ou sous forme python")
98                        self.editor.affiche_infos(commentaire)
99                        return listeValeurs,0
100                        
101
102                  else :     # ce n'est pas un tuple a la mode aster
103                     listeValeurs.append(v)
104                     indice = indice + 1
105
106            else:  # on n'attend pas un complexe
107              listeValeurs=valeurBrute.split(',')
108
109         elif type(valeur) == types.StringType:
110              listeValeurs=valeur.split(',')
111         else:
112           listeValeurs.append(valeurBrute)
113
114         return listeValeurs,1
115
116