Salome HOME
reindent + copyright + merge manuel avec la V9_dev sauf repertoires metier
[tools/eficas.git] / InterfaceQT4 / monWidgetSimpBase.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   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         if 'R' or 'I' in self.monSimpDef.type  : self.lineEditVal.setMinimumWidth(525)
44         self.parentQt.commandesLayout.insertWidget(-1,self,1)
45         self.setFocusPolicy(Qt.StrongFocus)
46         if monSimpDef.homo == 'constant' : self.lineEditVal.setReadOnly(True)
47         if monSimpDef.homo == 'constant' : self.lineEditVal.setStyleSheet("background:rgb(210,235,235);\n" "border:0px;")
48         else : self.lineEditVal.returnPressed.connect(self.LEvaleurPressed)
49         self.AAfficher=self.lineEditVal
50         self.maCommande.listeAffichageWidget.append(self.lineEditVal)
51         self.lineEditVal.focusInEvent=self.monFocusInEvent
52         self.lineEditVal.focusOutEvent=self.monFocusOutEvent
53
54
55     def monFocusInEvent(self,event):
56         self.editor.nodeEnCours = self
57         QLineEdit.focusInEvent(self.lineEditVal,event)
58
59     def monFocusOutEvent(self,event):
60         if self.oldValeurTexte != self.lineEditVal.text():
61             self.oldValeurTexte= self.lineEditVal.text()
62             self.LEvaleurPressed()
63         QLineEdit.focusOutEvent(self.lineEditVal,event)
64
65
66     def setValeurs(self):
67         #print ("dans setValeurs")
68         self.politique=PolitiqueUnique(self.node,self.editor)
69         valeur=self.node.item.getValeur()
70         valeurTexte=self.politique.getValeurTexte(valeur)
71         chaine=""
72
73         if valeurTexte != None :
74             from decimal import Decimal
75             if isinstance(valeurTexte,Decimal):
76                 chaine=str(valeurTexte)
77             elif repr(valeurTexte.__class__).find("PARAMETRE") > 0:
78                 chaine = repr(valeur)
79             else :
80                 #PN ????
81                 #try :
82                 #  chaine=QString("").setNum(valeurTexte)
83                 #except :
84                 chaine=str(valeurTexte)
85         self.oldValeurTexte=chaine
86         self.lineEditVal.setText(chaine)
87
88
89     def finCommentaire(self):
90         mc = self.objSimp.definition
91         d_aides = { 'TXM' : tr(u"Une chaine de caracteres est attendue.  "),
92                     'R'   : tr(u"Un reel est attendu. "),
93                     'I'   : tr(u"Un entier est attendu.  "),
94                     'Matrice' : tr(u'Une Matrice est attendue.  '),
95                     'Fichier' : tr(u'Un fichier est attendu.  '),
96                     'FichierNoAbs' : tr(u'Un fichier est attendu.  '),
97                     'Repertoire' : tr(u'Un repertoire est attendu.  '),
98                     'FichierOuRepertoire' : tr(u'Un repertoire ou un fichier est attendu.  '),
99                     'Heure' : tr(u'Heure sous la forme HH:MM'),
100                     'Date' :  tr(u'Date sous la forme JJ/MM/AA')}
101         if mc.type[0] != type:
102             commentaire = d_aides.get(mc.type[0], tr("Type de base inconnu"))
103         else : commentaire=""
104         return commentaire
105
106
107     def LEvaleurPressed(self):
108         # pour les soucis d encoding
109         try :
110             if str(self.lineEditVal.text())=="" or str(self.lineEditVal.text())==None : return
111         except : pass
112         SaisieValeur.LEvaleurPressed(self)
113         self.parentQt.donneFocus()
114         self.setValeurs()
115         self.reaffiche()