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
48 maPolice= QFont("Times", 10)
49 self.setFont(maPolice)
51 self.parentQt=parentQt
52 self.editor=self.node.editor
53 self.appliEficas=self.editor.appliEficas
54 self.repIcon=self.appliEficas.repIcon
55 self.monSimpDef=monSimpDef
58 self.node.fenetre=self
59 self.maCommande=commande
61 self.aRedimensionner=0
66 self.setIconePoubelle()
67 self.setIconesFichier()
68 self.setIconesSalome()
75 nomTraduit=tr(self.objSimp.nom)
76 #if len(nomTraduit) >= nomMax :
77 # nom=nomTraduit[0:nomMax]+'...'
78 # self.label.setText(nomTraduit)
79 # self.debutToolTip=nomTraduit+"\n"
80 longueur=QFontMetrics(self.label.font()).width(nomTraduit)
81 if longueur >= nomMax :
83 nouveauNom=self.formate(nomTraduit)
88 #self.label.setTextFormat(Qt.AutoText)
89 self.label.setText(nouveauNom)
92 self.label.setText(nomTraduit)
95 # inutile pour certains widgets
96 if self.height() < 40 :
98 self.setMinimumHeight(50)
99 #self.setMaximumHeight(50)
100 self.resize(self.width(),200)
101 #self.principalLayout.setAlignment(Qt.AlignTop)
102 #self.label.resize(self.label.width(),200)
103 print self.label.height()
108 def setValeurs(self):
109 # print "passe dans setValeurs pour ", self.objSimp.nom
110 # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
113 def finCommentaire(self):
116 def setSuggestion(self):
117 if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
118 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
119 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
121 def setCommentaire(self):
122 c = self.debutToolTip
123 if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
125 if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
126 c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
127 self.label.setToolTip(c2)
128 self.aide=str(self.objSimp.get_fr())+" "+c
130 c+=self.finCommentaire()
131 if c != "" and c != None :
133 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
134 c=str('<html><head/><body><p>')+c+"</p></body></html>"
135 self.label.setToolTip(c)
139 def showEvent(self, event):
140 if self.prendLeFocus==1 :
141 self.activateWindow()
142 "il faut deriver le showEvent pour" , self.nom
144 QWidget.showEvent(self,event)
146 def aideALaSaisie(self):
147 mc = self.node.item.get_definition()
149 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
152 'C' : tr("complexe"),
153 'Matrice' : tr(u'Matrice'),
154 'Fichier' : tr(u'fichier'),
155 'FichierNoAbs' : tr(u'fichier existant'),
156 'Repertoire' : tr(u'repertoire')}
158 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
159 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
161 if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
162 else: ctype = d_aides.get(mctype, tr("Type de base inconnu"))
163 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
166 if mc.max!=1 : commentaire+="s"
169 def setZoneInfo(self):
170 # info=str(self.nom)+' '
171 # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
172 # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
174 #self.editor.affiche_infos(info)
177 #print "dans reaffiche de feuille", self.nom
178 if self.editor.jdc.aReafficher==True :
179 #print " j appelle le reaffiche de parentQt"
180 self.parentQt.reaffiche()
182 #PN PN PN pas satisfaisant
183 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
184 #print nodeAVoir.fenetre
185 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
186 #if nodeAVoir.fenetre.isVisible() : return
187 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
188 #nodeAVoir.fenetre.setFocus()
189 # return # on est bien postionne
190 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
191 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
193 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
196 def traiteClicSurLabel(self,texte):
198 aide=self.aide+"\n"+self.aideALaSaisie()
199 self.editor.affiche_infos(aide)
203 newText=t[0:19]+'\n'+t[19:]
205 listeNom=t.split('_')
209 if len(ligne)+len(n) < 25 :
210 newTexte=newTexte+"_"+n
213 newTexte=newTexte+"\n_"+n
215 #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]