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
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
29 from gereIcones import ContientIcones
30 from gereIcones import FacultatifOuOptionnel
31 from qtSaisie import SaisieValeur
34 # ---------------------------------------------------------------------- #
35 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
36 # --------------------------------------------------------------------- #
39 def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
40 #print "Feuille", monSimpDef,nom,objSimp
42 QWidget.__init__(self,None)
44 self.node.fenetre=self
46 # on se positionne pour les icones
47 #os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__))))
51 maPolice= QFont("Times", 10)
52 self.setFont(maPolice)
54 self.parentQt=parentQt
55 self.editor=self.node.editor
56 self.appliEficas=self.editor.appliEficas
57 self.repIcon=self.appliEficas.repIcon
58 self.monSimpDef=monSimpDef
61 self.node.fenetre=self
62 self.maCommande=commande
64 self.aRedimensionner=0
69 self.setIconePoubelle()
70 self.setIconesFichier()
71 self.setIconesSalome()
72 self.setIconesGenerales()
79 nomTraduit=tr(self.objSimp.nom)
80 #if len(nomTraduit) >= nomMax :
81 # nom=nomTraduit[0:nomMax]+'...'
82 # self.label.setText(nomTraduit)
83 # self.debutToolTip=nomTraduit+"\n"
84 longueur=QFontMetrics(self.label.font()).width(nomTraduit)
85 if longueur >= nomMax :
86 nouveauNom=self.formate(nomTraduit)
87 self.label.setText(nouveauNom)
89 self.label.setText(nomTraduit)
92 # inutile pour certains widgets
93 if self.height() < 40 :
94 self.setMinimumHeight(50)
95 self.resize(self.width(),200)
99 # print "passe dans setValeurs pour ", self.objSimp.nom
100 # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
103 def finCommentaire(self):
106 def setSuggestion(self):
107 if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
108 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
109 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
111 def setCommentaire(self):
112 c = self.debutToolTip
113 #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
115 if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
116 c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
117 self.label.setToolTip(c2)
118 self.aide=str(self.objSimp.get_fr())+" "+c
120 c+=self.finCommentaire()
121 if c != "" and c != None :
123 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
124 c=str('<html><head/><body><p>')+c+"</p></body></html>"
125 self.label.setToolTip(c)
129 def showEvent(self, event):
130 if self.prendLeFocus==1 :
131 self.activateWindow()
132 "il faut deriver le showEvent pour" , self.nom
134 QWidget.showEvent(self,event)
136 def aideALaSaisie(self):
137 mc = self.node.item.get_definition()
139 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
142 'C' : tr("complexe"),
143 'Matrice' : tr(u'Matrice'),
144 'Fichier' : tr(u'fichier'),
145 'FichierNoAbs' : tr(u'fichier existant'),
146 'Repertoire' : tr(u'repertoire')}
148 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
149 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
151 if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
152 else: ctype = d_aides.get(mctype, tr("Type de base inconnu"))
153 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
156 if mc.max!=1 : commentaire+="s"
159 def setZoneInfo(self):
160 # info=str(self.nom)+' '
161 # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
162 # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
164 #self.editor.affiche_infos(info)
167 #print "dans reaffiche de feuille", self.nom
168 if self.editor.jdc.aReafficher==True :
169 #print " j appelle le reaffiche de parentQt"
170 self.parentQt.reaffiche()
172 #PN PN PN pas satisfaisant
173 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
174 #print nodeAVoir.fenetre
175 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
176 #if nodeAVoir.fenetre.isVisible() : return
177 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
178 #nodeAVoir.fenetre.setFocus()
179 # return # on est bien postionne
181 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
182 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
184 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
185 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
187 nodeAVoir.fenetre.setValeursApresBouton()
191 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
195 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
197 self.setValeursApresBouton()
199 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
201 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
203 def reaffichePourDeplier(self):
204 self.parentQt.reaffiche()
206 def rendVisible(self):
207 #print "jjjjjjjjjjjjjjjjjjjjj"
210 def traiteClicSurLabel(self,texte):
212 aide=self.aide+"\n"+self.aideALaSaisie()
213 self.editor.affiche_commentaire(aide)
217 newText=t[0:19]+'\n'+t[19:]
219 listeNom=t.split('_')
223 if len(ligne)+len(n) < 25 :
224 newTexte=newTexte+"_"+n
227 newTexte=newTexte+"\n_"+n
229 #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]