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'
129 commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
132 commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
134 commentaire=tr("Entrez entre ")+str(mc.min)+(" et ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
135 aideval=self.node.item.aide()
136 commentaire=commentaire + tr(aideval)
137 self.monCommentaireLabel.setText(str(commentaire))
138 return str(commentaire)
141 def setSuggestion(self):
142 if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
143 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
144 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
146 def setCommentaire(self):
147 c = self.debutToolTip
148 #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
150 if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
151 c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
152 self.label.setToolTip(c2)
153 self.aide=str(self.objSimp.get_fr())+" "+c
155 c+=self.finCommentaire()
156 if c != "" and c != None :
158 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
159 c=str('<html><head/><body><p>')+c+"</p></body></html>"
160 self.label.setToolTip(c)
164 def showEvent(self, event):
165 if self.prendLeFocus==1 :
166 self.activateWindow()
167 "il faut deriver le showEvent pour" , self.nom
169 QWidget.showEvent(self,event)
171 def aideALaSaisie(self):
172 mc = self.node.item.get_definition()
174 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
177 'C' : tr("complexe"),
178 'Matrice' : tr(u'Matrice'),
179 'Fichier' : tr(u'fichier'),
180 'FichierNoAbs' : tr(u'fichier existant'),
181 'Repertoire' : tr(u'repertoire')}
183 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
184 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
186 if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
187 else: ctype = d_aides.get(mctype, tr("Type de base inconnu"))
188 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
191 if mc.max!=1 : commentaire+="s"
194 def setZoneInfo(self):
195 # info=str(self.nom)+' '
196 # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
197 # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
199 #self.editor.affiche_infos(info)
202 #print "dans reaffiche de feuille", self.nom
203 if self.editor.jdc.aReafficher==True :
204 self.parentQt.reaffiche()
206 #PN PN PN pas satisfaisant
207 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
208 #print nodeAVoir.fenetre
209 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
210 #if nodeAVoir.fenetre.isVisible() : return
211 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
212 #nodeAVoir.fenetre.setFocus()
213 # return # on est bien postionne
215 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
216 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
218 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
219 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
221 nodeAVoir.fenetre.setValeursApresBouton()
225 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
229 if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
231 self.setValeursApresBouton()
233 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
235 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
237 def reaffichePourDeplier(self):
238 self.parentQt.reaffiche()
240 def rendVisible(self):
241 #print "jjjjjjjjjjjjjjjjjjjjj"
244 #def enterEvent(self,event):
245 # print "je passe dans enterEvent", self.nom
246 #if self.editor.code != "CARMELCND" :self.afficheOptionnel()
247 # QWidget.enterEvent(self,event)
249 def traiteClicSurLabel(self,texte):
251 aide=self.aide+"\n"+self.aideALaSaisie()
252 self.editor.affiche_commentaire(aide)
256 newText=t[0:19]+'\n'+t[19:]
258 listeNom=t.split('_')
262 if len(ligne)+len(n) < 25 :
263 newTexte=newTexte+"_"+n
266 newTexte=newTexte+"\n_"+n
268 #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]