1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 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 from __future__ import absolute_import
23 from builtins import str
29 from PyQt5.QtWidgets import QToolButton ,QWidget
30 from PyQt5.QtGui import QFont, QFontMetrics, QFontInfo, QPalette
31 from PyQt5.QtCore import Qt
33 from Extensions.i18n import tr
35 from .gereIcones import ContientIcones
36 from .gereIcones import FacultatifOuOptionnel
37 from .qtSaisie import SaisieValeur
40 # empirique les metrics ne fonctionnent pas
41 # ---------------------------------------------------------------------- #
42 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
43 # --------------------------------------------------------------------- #
46 def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
47 #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 if self.monSimpDef.unite == None :
87 if hasattr( self,'lineEditUnite') : self.lineEditUnite.setText(' ')
89 if hasattr( self,'lineEditUnite') : self.lineEditUnite.setText(self.monSimpDef.unite)
90 else : self.editor.informe('Erreur de Catalogue','Champ Unite non prevu pour '+ self.nom + ' correction du catalogue souhaitable, prevenez la maintenance', False)
93 if not (self.editor.appliEficas.maConfiguration.afficheUQ) and hasattr(self,'checkBoxUQ') :
94 self.checkBoxUQ.close()
96 if not self.monSimpDef.UQPossible():
97 self.checkBoxUQ.close()
99 if self.objSimp.isUQActivate() and hasattr(self,'checkBoxUQ') :
100 self.checkBoxUQ.setChecked(True)
104 nomTraduit=tr(self.objSimp.nom)
105 #metrix= QFontMetrics(self.label.font())
106 #maxLongueur = self.label.width() - 2
107 #print ('______________________')
109 #print (self.label.font().pixelSize())
110 #longueur2 = metrix.boundingRect(nomTraduit).width()
111 longueur=QFontMetrics(self.label.font()).width(nomTraduit)
112 if longueur >= nomMax :
113 nouveauNom=self.formate(nomTraduit)
114 self.label.setText(nouveauNom)
116 self.label.setText(nomTraduit)
117 #clidedText = metrics.elidedText(text, Qt.ElideRight, label.width());
118 #if (clippedText != nomTraduit): self.label.setToolTip(nomTraduit)
119 #self.label.setText(clippedText)
122 # inutile pour certains widgets
123 # if self.height() < 40 :
124 # self.setMinimumHeight(50)
125 # self.resize(self.width(),200)
127 #def mousePressEvent(self, event):
128 #print 'mousePressEvent'
130 #print (inspect.getmro(self.__class__))
131 #self.__class__.mousePressEvent(self, event)
135 def setValeurs(self):
136 # print "passe dans setValeurs pour ", self.objSimp.nom
137 # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
140 def finCommentaire(self):
144 def finCommentaireListe(self):
146 mc = self.node.item.get_definition()
147 d_aides = { 'TXM' : 'chaines de caracteres',
152 if not type in d_aides :
154 commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
157 commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
162 commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
163 elif mc.max == float('inf') :
164 commentaire=tr("Entrez une liste de ") +" "+tr(d_aides[type])+'\n'
166 commentaire=tr("Entrez entre ")+"\n"+str(mc.min)+(" et ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
167 aideval=self.node.item.aide()
168 commentaire=commentaire + tr(aideval)
169 return str(commentaire)
172 def setSuggestion(self):
173 if self.monSimpDef.getSug() != None and self.monSimpDef.getSug() != "":
174 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.getSug())+"</span></p></body></html>"
175 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
177 def setCommentaire(self):
178 c = self.debutToolTip
179 #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
181 if self.objSimp.getFr() != None and self.objSimp.getFr() != "":
182 #c2 = '<html><head/><body><p>'+c+self.objSimp.getFr().decode('latin-1','replace')+"</p></body></html>"
183 c2 = '<html><head/><body><p>'+c+self.objSimp.getFr()
184 #c2 = '<html><head/><body><p>'+c+self.objSimp.getFr()+"</p></body></html>"
185 self.label.setToolTip(c2)
186 #self.aide=self.objSimp.getFr().decode('latin-1','ignore')+" "+c
187 self.aide=self.objSimp.getFr()+" "+c
189 c+=self.finCommentaire()
190 if c != "" and c != None :
192 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
193 c=str('<html><head/><body><p>')+c+"</p></body></html>"
194 self.label.setToolTip(c)
196 if self.editor.maConfiguration.differencieSiDefaut :
197 self.label.setToolTip('defaut : ' + tr(str(self.node.item.object.definition.defaut)))
201 def showEvent(self, event):
202 if self.prendLeFocus==1 :
203 self.activateWindow()
204 "il faut deriver le showEvent pour" , self.nom
206 QWidget.showEvent(self,event)
208 def aideALaSaisie(self):
209 mc = self.node.item.get_definition()
211 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
214 'C' : tr("complexe"),
215 'Matrice' : tr(u'Matrice'),
216 'Fichier' : tr(u'fichier'),
217 'FichierNoAbs' : tr(u'fichier existant'),
218 'Repertoire' : tr(u'repertoire')}
220 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
221 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max) + " "
224 if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
225 else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
227 ctype = d_aides.get(mctype, tr("Type de base inconnu"))
228 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
229 if ctype == tr("Type de base inconnu") and "bool" in str(mctype): ctype='bool'
232 if ctype == 'chaine de caractere' and mc.max>1 : ctype = 'chaines de caractere'
233 else : ctype = ctype + 's'
235 if mc.max!=1 : commentaire+="s"
238 def setZoneInfo(self):
239 # info=str(self.nom)+' '
240 # if self.monSimpDef.getFr() != None and self.monSimpDef.getFr() != "": info+=self.monSimpDef.getSug() +" "
241 # if self.monSimpDef.getSug() != None and self.monSimpDef.getSug() != "": info+="Valeur suggeree : "self.monSimpDef.getSug()
246 if self.editor.jdc.aReafficher==True :
247 self.parentQt.reaffiche()
249 #PN PN PN pas satisfaisant
250 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
251 #print nodeAVoir.fenetre
252 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
253 #if nodeAVoir.fenetre.isVisible() : return
254 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
255 #nodeAVoir.fenetre.setFocus()
256 # return # on est bien postionne
258 if self.objSimp.isValid() and hasattr(self, 'AAfficher'):
259 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
261 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
262 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
264 nodeAVoir.fenetre.setValeursApresBouton()
268 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
272 if self.objSimp.isValid() and hasattr(self, 'AAfficher'):
274 self.setValeursApresBouton()
277 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
279 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
281 def reaffichePourDeplier(self):
282 self.parentQt.reaffiche()
284 def rendVisible(self):
287 #def enterEvent(self,event):
288 # print "je passe dans enterEvent", self.nom
289 # QWidget.enterEvent(self,event)
291 def traiteClicSurLabel(self,texte):
292 #aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
294 aide=self.aide+"\n"+self.aideALaSaisie()
296 aide=self.aideALaSaisie()
297 self.editor.afficheCommentaire(aide)
301 newText=t[0:l]+'-\n'+t[l:]