Salome HOME
linux/windows
[tools/eficas.git] / InterfaceQT4 / monWidgetSimpBase.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 desWidgetSimpBase     import Ui_WidgetSimpBase 
30 from politiquesValidation  import PolitiqueUnique
31 from qtSaisie              import SaisieValeur
32
33
34 class MonWidgetSimpBase (Ui_WidgetSimpBase,Feuille):
35
36   def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
37         Feuille.__init__(self,node,monSimpDef,nom,objSimp,parentQt,commande)
38         #print "MonWidgetSimpBase", nom
39         self.parentQt.commandesLayout.insertWidget(-1,self)
40         self.setFocusPolicy(Qt.StrongFocus)
41         self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.LEValeurPressed)
42         self.AAfficher=self.lineEditVal
43         self.maCommande.listeAffichageWidget.append(self.lineEditVal)
44
45
46   #def showEvent(self, event):
47   #    if self.prendLeFocus==1 :
48   #       self.activateWindow()
49   #       self.lineEditVal.setFocus()
50   #       self.prendLeFocus=0
51   #    QWidget.showEvent(self,event)
52
53   def setValeurs(self):
54        self.politique=PolitiqueUnique(self.node,self.editor)
55        valeur=self.node.item.get_valeur()
56        valeurTexte=self.politique.GetValeurTexte(valeur)
57        chaine=QString("")
58
59        if valeurTexte != None :
60           from decimal import Decimal
61           if isinstance(valeurTexte,Decimal):
62              chaine=str(valeurTexte)
63           elif repr(valeurTexte.__class__).find("PARAMETRE") > 0:
64              chaine = QString(repr(valeur))
65           else :
66              #PN ????
67              #try :
68              #  chaine=QString("").setNum(valeurTexte)
69              #except :
70              chaine=QString(str(valeurTexte))
71        self.lineEditVal.setText(chaine)
72
73
74   def finCommentaire(self):
75       mc = self.objSimp.definition
76       d_aides = { 'TXM' : tr(u"Une chaine de caracteres est attendue.  "),
77                   'R'   : tr(u"Un reel est attendu. "),
78                   'I'   : tr(u"Un entier est attendu.  "),
79                   'Matrice' : tr(u'Une Matrice est attendue.  '),
80                   'Fichier' : tr(u'Un fichier est attendu.  '),
81                   'FichierNoAbs' : tr(u'Un fichier est attendu.  '),
82                   'Repertoire' : tr(u'Un repertoire est attendu.  '),
83                   'Heure' : tr(u'Heure sous la forme HH:MM'),
84                   'Date' :  tr(u'Date sous la forme JJ/MM/AA')}
85       if mc.type[0] != types.ClassType:
86          commentaire = d_aides.get(mc.type[0], tr("Type de base inconnu"))
87       else : commentaire=""
88       return commentaire
89
90
91   def LEValeurPressed(self):
92       if str(self.lineEditVal.text())=="" or str(self.lineEditVal.text())==None : return
93       SaisieValeur.LEValeurPressed(self)
94       self.parentQt.donneFocus()
95       self.setValeurs()
96       self.reaffiche()
97       
98       #if self.objSimp.parent.nom == "MODEL" :
99       #   if self.objSimp.isvalid():
100       #      self.objSimp.parent.change_fichier="1"
101             #self.node.item.parent.build_include(None,"")
102