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, QFontInfo, QPalette
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 # empirique les metrics ne fonctionnent pas
41 # ---------------------------------------------------------------------- #
42 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
43 # --------------------------------------------------------------------- #
46 def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
47 #print ("Feuille", monSimpDef,nom,objSimp)
48 QWidget.__init__(self,None)
50 self.node.fenetre=self
52 # on se positionne pour les icones
53 #os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__))))
57 maPolice= QFont("Times", 10)
58 self.setFont(maPolice)
59 self.setFocusPolicy(Qt.StrongFocus)
61 self.parentQt=parentQt
62 self.editor=self.node.editor
63 self.appliEficas=self.editor.appliEficas
64 self.repIcon=self.appliEficas.repIcon
65 self.monSimpDef=monSimpDef
68 self.node.fenetre=self
69 self.maCommande=commande
71 self.aRedimensionner=0
76 self.setIconePoubelle()
77 self.setIconesFichier()
78 self.setIconesSalome()
79 self.setIconesGenerales()
86 nomTraduit=tr(self.objSimp.nom)
87 #metrix= QFontMetrics(self.label.font())
88 #maxLongueur = self.label.width() - 2
89 #print ('______________________')
91 #print (self.label.font().pixelSize())
92 #longueur2 = metrix.boundingRect(nomTraduit).width()
93 longueur=QFontMetrics(self.label.font()).width(nomTraduit)
94 if longueur >= nomMax :
95 nouveauNom=self.formate(nomTraduit)
96 self.label.setText(nouveauNom)
98 self.label.setText(nomTraduit)
99 #clidedText = metrics.elidedText(text, Qt.ElideRight, label.width());
100 #if (clippedText != nomTraduit): self.label.setToolTip(nomTraduit)
101 #self.label.setText(clippedText)
104 # inutile pour certains widgets
105 # if self.height() < 40 :
106 # self.setMinimumHeight(50)
107 # self.resize(self.width(),200)
109 #def mousePressEvent(self, event):
110 #print 'mousePressEvent'
112 #print (inspect.getmro(self.__class__))
113 #self.__class__.mousePressEvent(self, event)
117 def setValeurs(self):
118 # print "passe dans setValeurs pour ", self.objSimp.nom
119 # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
122 def finCommentaire(self):
126 def finCommentaireListe(self):
128 mc = self.node.item.get_definition()
129 d_aides = { 'TXM' : 'chaines de caracteres',
134 if not type in d_aides :
136 commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
139 commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
144 commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
145 elif mc.max == float('inf') :
146 commentaire=tr("Entrez une liste de ") + tr(d_aides[type])+'\n'
148 commentaire=tr("Entrez entre ")+"\n"+str(mc.min)+(" et ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
149 aideval=self.node.item.aide()
150 commentaire=commentaire + tr(aideval)
151 return str(commentaire)
154 def setSuggestion(self):
155 if self.monSimpDef.getSug() != None and self.monSimpDef.getSug() != "":
156 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.getSug())+"</span></p></body></html>"
157 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
159 def setCommentaire(self):
160 c = self.debutToolTip
161 #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
163 if self.objSimp.getFr() != None and self.objSimp.getFr() != "":
164 #c2 = '<html><head/><body><p>'+c+self.objSimp.getFr().decode('latin-1','replace')+"</p></body></html>"
165 c2 = '<html><head/><body><p>'+c+self.objSimp.getFr()
166 #c2 = '<html><head/><body><p>'+c+self.objSimp.getFr()+"</p></body></html>"
167 self.label.setToolTip(c2)
168 #self.aide=self.objSimp.getFr().decode('latin-1','ignore')+" "+c
169 self.aide=self.objSimp.getFr()+" "+c
171 c+=self.finCommentaire()
172 if c != "" and c != None :
174 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
175 c=str('<html><head/><body><p>')+c+"</p></body></html>"
176 self.label.setToolTip(c)
177 if self.editor.maConfiguration.differencieSiDefaut :
178 self.label.setToolTip('defaut : ' + tr(str(self.node.item.object.definition.defaut)))
183 def showEvent(self, event):
184 if self.prendLeFocus==1 :
185 self.activateWindow()
186 "il faut deriver le showEvent pour" , self.nom
188 QWidget.showEvent(self,event)
190 def aideALaSaisie(self):
191 mc = self.node.item.get_definition()
193 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
196 'C' : tr("complexe"),
197 'Matrice' : tr(u'Matrice'),
198 'Fichier' : tr(u'fichier'),
199 'FichierNoAbs' : tr(u'fichier existant'),
200 'Repertoire' : tr(u'repertoire')}
202 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
203 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
206 if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
207 else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
209 ctype = d_aides.get(mctype, tr("Type de base inconnu"))
210 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
213 if mc.max!=1 : commentaire+="s"
216 def setZoneInfo(self):
217 # info=str(self.nom)+' '
218 # if self.monSimpDef.getFr() != None and self.monSimpDef.getFr() != "": info+=self.monSimpDef.getSug() +" "
219 # if self.monSimpDef.getSug() != None and self.monSimpDef.getSug() != "": info+="Valeur suggeree : "self.monSimpDef.getSug()
224 if self.editor.jdc.aReafficher==True :
225 self.parentQt.reaffiche()
227 #PN PN PN pas satisfaisant
228 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
229 #print nodeAVoir.fenetre
230 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
231 #if nodeAVoir.fenetre.isVisible() : return
232 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
233 #nodeAVoir.fenetre.setFocus()
234 # return # on est bien postionne
236 if self.objSimp.isValid() and hasattr(self, 'AAfficher'):
237 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
239 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
240 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
242 nodeAVoir.fenetre.setValeursApresBouton()
246 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
250 if self.objSimp.isValid() and hasattr(self, 'AAfficher'):
252 self.setValeursApresBouton()
255 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
257 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
259 def reaffichePourDeplier(self):
260 self.parentQt.reaffiche()
262 def rendVisible(self):
265 #def enterEvent(self,event):
266 # print "je passe dans enterEvent", self.nom
267 # QWidget.enterEvent(self,event)
269 def traiteClicSurLabel(self,texte):
270 #aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
272 aide=self.aide+"\n"+self.aideALaSaisie()
274 aide=self.aideALaSaisie()
275 self.editor.afficheCommentaire(aide)
279 newText=t[0:l]+'-\n'+t[l:]