Salome HOME
cb79fd3e3011286faa48f613ee00376e591807b4
[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         self.parentQt.commandesLayout.insertWidget(-1,self)
39         self.setFocusPolicy(Qt.StrongFocus)
40         self.connect(self.lineEditVal,SIGNAL("returnPressed()"),self.LEValeurPressed)
41         self.maCommande.listeAffichageWidget.append(self.lineEditVal)
42
43   def showEvent(self, event):
44       if self.prendLeFocus==1 :
45          self.activateWindow()
46          self.lineEditVal.setFocus()
47          self.prendLeFocus=0
48       QWidget.showEvent(self,event)
49
50   def setValeurs(self):
51        self.politique=PolitiqueUnique(self.node,self.editor)
52        valeur=self.node.item.get_valeur()
53        valeurTexte=self.politique.GetValeurTexte(valeur)
54        chaine=QString("")
55
56        if valeurTexte != None :
57           from decimal import Decimal
58           if isinstance(valeurTexte,Decimal):
59              chaine=str(valeurTexte)
60           elif repr(valeurTexte.__class__).find("PARAMETRE") > 0:
61              chaine = QString(repr(valeur))
62           else :
63              #PN ????
64              #try :
65              #  chaine=QString("").setNum(valeurTexte)
66              #except :
67              chaine=QString(str(valeurTexte))
68        self.lineEditVal.setText(chaine)
69
70
71   def finCommentaire(self):
72       mc = self.objSimp.definition
73       d_aides = { 'TXM' : tr(u"Une chaine de caracteres est attendue.  "),
74                   'R'   : tr(u"Un reel est attendu. "),
75                   'I'   : tr(u"Un entier est attendu.  "),
76                   'Matrice' : tr(u'Une Matrice est attendue.  '),
77                   'Fichier' : tr(u'Un fichier est attendu.  '),
78                   'FichierNoAbs' : tr(u'Un fichier est attendu.  '),
79                   'Repertoire' : tr(u'Un repertoire est attendu.  ')}
80       if mc.type[0] != types.ClassType:
81          commentaire = d_aides.get(mc.type[0], tr("Type de base inconnu"))
82       else : commentaire=""
83       return commentaire
84
85
86   def LEValeurPressed(self):
87       if str(self.lineEditVal.text())=="" or str(self.lineEditVal.text())==None : return
88       SaisieValeur.LEValeurPressed(self)
89       self.parentQt.donneFocus()
90       self.setValeurs()
91       
92       #if self.objSimp.parent.nom == "MODEL" :
93       #   if self.objSimp.isvalid():
94       #      self.objSimp.parent.change_fichier="1"
95             #self.node.item.parent.build_include(None,"")
96