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