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