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 QToolButton ,QWidget
30 from PyQt5.QtGui import QFont, QFontMetrics
31 from PyQt5.QtCore import Qt
33 from Extensions.i18n import tr
35 from .gereIcones import ContientIcones
36 from .gereIcones import FacultatifOuOptionnel
37 from .qtSaisie import SaisieValeur
40 # ---------------------------------------------------------------------- #
41 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
42 # --------------------------------------------------------------------- #
45 def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
46 #print ("Feuille", monSimpDef,nom,objSimp)
47 QWidget.__init__(self,None)
49 self.node.fenetre=self
51 # on se positionne pour les icones
52 #os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__))))
56 maPolice= QFont("Times", 10)
57 self.setFont(maPolice)
58 self.setFocusPolicy(Qt.StrongFocus)
60 self.parentQt=parentQt
61 self.editor=self.node.editor
62 self.appliEficas=self.editor.appliEficas
63 self.repIcon=self.appliEficas.repIcon
64 self.monSimpDef=monSimpDef
67 self.node.fenetre=self
68 self.maCommande=commande
70 self.aRedimensionner=0
75 self.setIconePoubelle()
76 self.setIconesFichier()
77 self.setIconesSalome()
78 self.setIconesGenerales()
85 nomTraduit=tr(self.objSimp.nom)
86 longueur=QFontMetrics(self.label.font()).width(nomTraduit)
87 if longueur >= nomMax :
88 nouveauNom=self.formate(nomTraduit)
89 self.label.setText(nouveauNom)
91 self.label.setText(nomTraduit)
94 # inutile pour certains widgets
95 if self.height() < 40 :
96 self.setMinimumHeight(50)
97 self.resize(self.width(),200)
99 #def mousePressEvent(self, event):
100 #print 'mousePressEvent'
102 #print (inspect.getmro(self.__class__))
103 #self.__class__.mousePressEvent(self, event)
107 def setValeurs(self):
108 # print "passe dans setValeurs pour ", self.objSimp.nom
109 # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
112 def finCommentaire(self):
116 def finCommentaireListe(self):
118 mc = self.node.item.get_definition()
119 d_aides = { 'TXM' : 'chaines de caracteres',
124 if not type in d_aides :
126 commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
129 commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
134 commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
136 commentaire=tr("Entrez entre ")+"\n"+str(mc.min)+(" et ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
137 aideval=self.node.item.aide()
138 commentaire=commentaire + tr(aideval)
139 self.monCommentaireLabel.setText(str(commentaire))
140 return str(commentaire)
143 def setSuggestion(self):
144 if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
145 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
146 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
148 def setCommentaire(self):
149 c = self.debutToolTip
150 #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
152 if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
153 #c2 = '<html><head/><body><p>'+c+self.objSimp.get_fr().decode('latin-1','replace')+"</p></body></html>"
154 c2 = '<html><head/><body><p>'+c+self.objSimp.get_fr()
155 #c2 = '<html><head/><body><p>'+c+self.objSimp.get_fr()+"</p></body></html>"
156 self.label.setToolTip(c2)
157 #self.aide=self.objSimp.get_fr().decode('latin-1','ignore')+" "+c
158 self.aide=self.objSimp.get_fr()+" "+c
160 c+=self.finCommentaire()
161 if c != "" and c != None :
163 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
164 c=str('<html><head/><body><p>')+c+"</p></body></html>"
165 self.label.setToolTip(c)
169 def showEvent(self, event):
170 if self.prendLeFocus==1 :
171 self.activateWindow()
172 "il faut deriver le showEvent pour" , self.nom
174 QWidget.showEvent(self,event)
176 def aideALaSaisie(self):
177 mc = self.node.item.get_definition()
179 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
182 'C' : tr("complexe"),
183 'Matrice' : tr(u'Matrice'),
184 'Fichier' : tr(u'fichier'),
185 'FichierNoAbs' : tr(u'fichier existant'),
186 'Repertoire' : tr(u'repertoire')}
188 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
189 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
192 if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
193 else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
195 ctype = d_aides.get(mctype, tr("Type de base inconnu"))
196 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
199 if mc.max!=1 : commentaire+="s"
202 def setZoneInfo(self):
203 # info=str(self.nom)+' '
204 # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
205 # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggeree : "self.monSimpDef.get_sug()
210 if self.editor.jdc.aReafficher==True :
211 self.parentQt.reaffiche()
213 #PN PN PN pas satisfaisant
214 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
215 #print nodeAVoir.fenetre
216 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
217 #if nodeAVoir.fenetre.isVisible() : return
218 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
219 #nodeAVoir.fenetre.setFocus()
220 # return # on est bien postionne
222 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
223 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
225 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
226 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
228 nodeAVoir.fenetre.setValeursApresBouton()
232 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
236 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
238 self.setValeursApresBouton()
241 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
243 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
245 def reaffichePourDeplier(self):
246 self.parentQt.reaffiche()
248 def rendVisible(self):
251 #def enterEvent(self,event):
252 # print "je passe dans enterEvent", self.nom
253 # QWidget.enterEvent(self,event)
255 def traiteClicSurLabel(self,texte):
256 aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
257 self.editor.affiche_commentaire(aide)
261 newText=t[0:19]+'\n'+t[19:]
263 listeNom=t.split('_')
267 if len(ligne)+len(n) < 25 :
268 newTexte=newTexte+"_"+n
271 newTexte=newTexte+"\n_"+n
273 #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]