1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from __future__ import absolute_import
23 from builtins import str
29 from PyQt5.QtWidgets import QLineEdit
30 from PyQt5.QtCore import Qt
31 from Extensions.i18n import tr
33 from .feuille import Feuille
34 from desWidgetSimpBase import Ui_WidgetSimpBase
35 from .politiquesValidation import PolitiqueUnique
36 from .qtSaisie import SaisieValeur
39 class MonWidgetSimpBase (Ui_WidgetSimpBase,Feuille):
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 if monSimpDef.homo == 'constant' : self.lineEditVal.setReadOnly(True)
46 if monSimpDef.homo == 'constant' : self.lineEditVal.setStyleSheet("background:rgb(210,235,235);\n" "border:0px;")
47 else : self.lineEditVal.returnPressed.connect(self.LEvaleurPressed)
48 self.AAfficher=self.lineEditVal
49 self.maCommande.listeAffichageWidget.append(self.lineEditVal)
50 self.lineEditVal.focusInEvent=self.monFocusInEvent
51 self.lineEditVal.focusOutEvent=self.monFocusOutEvent
54 def monFocusInEvent(self,event):
55 self.editor.nodeEnCours = self
56 QLineEdit.focusInEvent(self.lineEditVal,event)
58 def monFocusOutEvent(self,event):
59 if self.oldValeurTexte != self.lineEditVal.text():
60 self.oldValeurTexte= self.lineEditVal.text()
61 self.LEvaleurPressed()
62 QLineEdit.focusOutEvent(self.lineEditVal,event)
66 #print ("dans setValeurs")
67 self.politique=PolitiqueUnique(self.node,self.editor)
68 valeur=self.node.item.getValeur()
69 valeurTexte=self.politique.getValeurTexte(valeur)
72 if valeurTexte != None :
73 from decimal import Decimal
74 if isinstance(valeurTexte,Decimal):
75 chaine=str(valeurTexte)
76 elif repr(valeurTexte.__class__).find("PARAMETRE") > 0:
81 # chaine=QString("").setNum(valeurTexte)
83 chaine=str(valeurTexte)
84 self.oldValeurTexte=chaine
85 self.lineEditVal.setText(chaine)
88 def finCommentaire(self):
89 mc = self.objSimp.definition
90 d_aides = { 'TXM' : tr(u"Une chaine de caracteres est attendue. "),
91 'R' : tr(u"Un reel est attendu. "),
92 'I' : tr(u"Un entier est attendu. "),
93 'Matrice' : tr(u'Une Matrice est attendue. '),
94 'Fichier' : tr(u'Un fichier est attendu. '),
95 'FichierNoAbs' : tr(u'Un fichier est attendu. '),
96 'Repertoire' : tr(u'Un repertoire est attendu. '),
97 'FichierOuRepertoire' : tr(u'Un repertoire ou un fichier est attendu. '),
98 'Heure' : tr(u'Heure sous la forme HH:MM'),
99 'Date' : tr(u'Date sous la forme JJ/MM/AA')}
100 if mc.type[0] != type:
101 commentaire = d_aides.get(mc.type[0], tr("Type de base inconnu"))
102 else : commentaire=""
106 def LEvaleurPressed(self):
107 # pour les soucis d encoding
109 if str(self.lineEditVal.text())=="" or str(self.lineEditVal.text())==None : return
111 SaisieValeur.LEvaleurPressed(self)
112 self.parentQt.donneFocus()