1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 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 ")+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 self.label.setToolTip(c2)
155 self.aide=self.objSimp.get_fr().decode('latin-1','ignore')+" "+c
157 c+=self.finCommentaire()
158 if c != "" and c != None :
160 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
161 c=str('<html><head/><body><p>')+c+"</p></body></html>"
162 self.label.setToolTip(c)
166 def showEvent(self, event):
167 if self.prendLeFocus==1 :
168 self.activateWindow()
169 "il faut deriver le showEvent pour" , self.nom
171 QWidget.showEvent(self,event)
173 def aideALaSaisie(self):
174 mc = self.node.item.get_definition()
176 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
179 'C' : tr("complexe"),
180 'Matrice' : tr(u'Matrice'),
181 'Fichier' : tr(u'fichier'),
182 'FichierNoAbs' : tr(u'fichier existant'),
183 'Repertoire' : tr(u'repertoire')}
185 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
186 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
189 if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
190 else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
192 ctype = d_aides.get(mctype, tr("Type de base inconnu"))
193 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
196 if mc.max!=1 : commentaire+="s"
199 def setZoneInfo(self):
200 # info=str(self.nom)+' '
201 # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
202 # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggeree : "self.monSimpDef.get_sug()
207 if self.editor.jdc.aReafficher==True :
208 self.parentQt.reaffiche()
210 #PN PN PN pas satisfaisant
211 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
212 #print nodeAVoir.fenetre
213 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
214 #if nodeAVoir.fenetre.isVisible() : return
215 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
216 #nodeAVoir.fenetre.setFocus()
217 # return # on est bien postionne
219 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
220 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
222 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
223 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
225 nodeAVoir.fenetre.setValeursApresBouton()
229 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
233 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
235 self.setValeursApresBouton()
238 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
240 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
242 def reaffichePourDeplier(self):
243 self.parentQt.reaffiche()
245 def rendVisible(self):
248 #def enterEvent(self,event):
249 # print "je passe dans enterEvent", self.nom
250 # QWidget.enterEvent(self,event)
252 def traiteClicSurLabel(self,texte):
253 aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
254 self.editor.affiche_commentaire(aide)
258 newText=t[0:19]+'\n'+t[19:]
260 listeNom=t.split('_')
264 if len(ligne)+len(n) < 25 :
265 newTexte=newTexte+"_"+n
268 newTexte=newTexte+"\n_"+n
270 #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]