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 import string,types,os
24 from determine import monEnvQT5
26 from PyQt5.QtWidgets import QToolButton ,QWidget
27 from PyQt5.QtGui import QFont, QFontMetrics
28 from PyQt5.QtCore import Qt
30 from PyQt4.QtGui import *
31 from PyQt4.QtCore import *
32 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
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 #print "kkkkkkkkkkkkkkkkkk"
87 #print self.objSimp.nom
88 nomTraduit=tr(self.objSimp.nom)
90 #if len(nomTraduit) >= nomMax :
91 # nom=nomTraduit[0:nomMax]+'...'
92 # self.label.setText(nomTraduit)
93 # self.debutToolTip=nomTraduit+"\n"
94 longueur=QFontMetrics(self.label.font()).width(nomTraduit)
95 if longueur >= nomMax :
96 nouveauNom=self.formate(nomTraduit)
97 self.label.setText(nouveauNom)
99 self.label.setText(nomTraduit)
102 # inutile pour certains widgets
103 if self.height() < 40 :
104 self.setMinimumHeight(50)
105 self.resize(self.width(),200)
108 def setValeurs(self):
109 # print "passe dans setValeurs pour ", self.objSimp.nom
110 # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
113 def finCommentaire(self):
117 def finCommentaireListe(self):
119 mc = self.node.item.get_definition()
120 d_aides = { 'TXM' : 'chaines de caracteres',
125 if not d_aides.has_key(type) :
127 commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
130 commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
135 commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
137 commentaire=tr("Entrez entre ")+str(mc.min)+(" et ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
138 aideval=self.node.item.aide()
139 commentaire=commentaire + tr(aideval)
140 self.monCommentaireLabel.setText(str(commentaire))
141 return str(commentaire)
144 def setSuggestion(self):
145 if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
146 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
147 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
149 def setCommentaire(self):
150 c = self.debutToolTip
151 #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
153 if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
154 c2 = '<html><head/><body><p>'+c+unicode(self.objSimp.get_fr())+"</p></body></html>"
155 self.label.setToolTip(c2)
156 self.aide=unicode(self.objSimp.get_fr())+" "+c
158 c+=self.finCommentaire()
159 if c != "" and c != None :
161 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
162 c=str('<html><head/><body><p>')+c+"</p></body></html>"
163 self.label.setToolTip(c)
167 def showEvent(self, event):
168 if self.prendLeFocus==1 :
169 self.activateWindow()
170 "il faut deriver le showEvent pour" , self.nom
172 QWidget.showEvent(self,event)
174 def aideALaSaisie(self):
175 mc = self.node.item.get_definition()
177 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
180 'C' : tr("complexe"),
181 'Matrice' : tr(u'Matrice'),
182 'Fichier' : tr(u'fichier'),
183 'FichierNoAbs' : tr(u'fichier existant'),
184 'Repertoire' : tr(u'repertoire')}
186 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
187 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
189 if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
190 else: ctype = d_aides.get(mctype, tr("Type de base inconnu"))
191 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
194 if mc.max!=1 : commentaire+="s"
197 def setZoneInfo(self):
198 # info=str(self.nom)+' '
199 # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
200 # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
204 #print "dans reaffiche de feuille", self.nom
205 if self.editor.jdc.aReafficher==True :
206 self.parentQt.reaffiche()
208 #PN PN PN pas satisfaisant
209 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
210 #print nodeAVoir.fenetre
211 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
212 #if nodeAVoir.fenetre.isVisible() : return
213 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
214 #nodeAVoir.fenetre.setFocus()
215 # return # on est bien postionne
217 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
218 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
220 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
221 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
223 nodeAVoir.fenetre.setValeursApresBouton()
227 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
231 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
233 self.setValeursApresBouton()
235 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
237 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
239 def reaffichePourDeplier(self):
240 self.parentQt.reaffiche()
242 def rendVisible(self):
243 #print "jjjjjjjjjjjjjjjjjjjjj"
246 #def enterEvent(self,event):
247 # print "je passe dans enterEvent", self.nom
248 # QWidget.enterEvent(self,event)
250 def traiteClicSurLabel(self,texte):
252 aide=self.aide+"\n"+self.aideALaSaisie()
253 self.editor.affiche_commentaire(aide)
257 newText=t[0:19]+'\n'+t[19:]
259 listeNom=t.split('_')
263 if len(ligne)+len(n) < 25 :
264 newTexte=newTexte+"_"+n
267 newTexte=newTexte+"\n_"+n
269 #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]