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 nomTraduit=tr(self.objSimp.nom)
87 #if len(nomTraduit) >= nomMax :
88 # nom=nomTraduit[0:nomMax]+'...'
89 # self.label.setText(nomTraduit)
90 # self.debutToolTip=nomTraduit+"\n"
91 longueur=QFontMetrics(self.label.font()).width(nomTraduit)
92 if longueur >= nomMax :
93 nouveauNom=self.formate(nomTraduit)
94 self.label.setText(nouveauNom)
96 self.label.setText(nomTraduit)
99 # inutile pour certains widgets
100 if self.height() < 40 :
101 self.setMinimumHeight(50)
102 self.resize(self.width(),200)
105 def setValeurs(self):
106 # print "passe dans setValeurs pour ", self.objSimp.nom
107 # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
110 def finCommentaire(self):
114 def finCommentaireListe(self):
116 mc = self.node.item.get_definition()
117 d_aides = { 'TXM' : 'chaines de caracteres',
122 if not d_aides.has_key(type) :
124 commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
126 commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
129 commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
131 commentaire=tr("Entrez entre ")+str(mc.min)+(" et ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
132 aideval=self.node.item.aide()
133 commentaire=commentaire + tr(aideval)
134 self.monCommentaireLabel.setText(str(commentaire))
135 return str(commentaire)
138 def setSuggestion(self):
139 if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
140 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
141 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
143 def setCommentaire(self):
144 c = self.debutToolTip
145 #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
147 if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
148 c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
149 self.label.setToolTip(c2)
150 self.aide=str(self.objSimp.get_fr())+" "+c
152 c+=self.finCommentaire()
153 if c != "" and c != None :
155 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
156 c=str('<html><head/><body><p>')+c+"</p></body></html>"
157 self.label.setToolTip(c)
161 def showEvent(self, event):
162 if self.prendLeFocus==1 :
163 self.activateWindow()
164 "il faut deriver le showEvent pour" , self.nom
166 QWidget.showEvent(self,event)
168 def aideALaSaisie(self):
169 mc = self.node.item.get_definition()
171 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
174 'C' : tr("complexe"),
175 'Matrice' : tr(u'Matrice'),
176 'Fichier' : tr(u'fichier'),
177 'FichierNoAbs' : tr(u'fichier existant'),
178 'Repertoire' : tr(u'repertoire')}
180 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
181 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
183 if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
184 else: ctype = d_aides.get(mctype, tr("Type de base inconnu"))
185 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
188 if mc.max!=1 : commentaire+="s"
191 def setZoneInfo(self):
192 # info=str(self.nom)+' '
193 # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
194 # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
196 #self.editor.affiche_infos(info)
199 #print "dans reaffiche de feuille", self.nom
200 if self.editor.jdc.aReafficher==True :
201 self.parentQt.reaffiche()
203 #PN PN PN pas satisfaisant
204 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
205 #print nodeAVoir.fenetre
206 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
207 #if nodeAVoir.fenetre.isVisible() : return
208 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
209 #nodeAVoir.fenetre.setFocus()
210 # return # on est bien postionne
212 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
213 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
215 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
216 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
218 nodeAVoir.fenetre.setValeursApresBouton()
222 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
226 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
228 self.setValeursApresBouton()
230 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
232 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
234 def reaffichePourDeplier(self):
235 self.parentQt.reaffiche()
237 def rendVisible(self):
238 #print "jjjjjjjjjjjjjjjjjjjjj"
241 #def enterEvent(self,event):
242 # print "je passe dans enterEvent", self.nom
243 #if self.editor.code != "CARMELCND" :self.afficheOptionnel()
244 # QWidget.enterEvent(self,event)
246 def traiteClicSurLabel(self,texte):
248 aide=self.aide+"\n"+self.aideALaSaisie()
249 self.editor.affiche_commentaire(aide)
253 newText=t[0:19]+'\n'+t[19:]
255 listeNom=t.split('_')
259 if len(ligne)+len(n) < 25 :
260 newTexte=newTexte+"_"+n
263 newTexte=newTexte+"\n_"+n
265 #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]