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()
87 if self.monSimpDef.unite == None :
88 if hasattr( self,'lineEditUnite') : self.lineEditUnite.setText(' ')
90 if hasattr( self,'lineEditUnite') : self.lineEditUnite.setText(self.monSimpDef.unite)
91 else : self.editor.informe('Erreur de Catalogue','Champ Unite non prevu pour '+ self.nom + ' correction du catalogue souhaitable, prevenez la maintenance', False)
94 if not (self.editor.appliEficas.maConfiguration.afficheUQ) and hasattr(self,'checkBoxUQ') :
95 self.checkBoxUQ.close()
97 if not self.monSimpDef.UQPossible():
98 self.checkBoxUQ.close()
100 if self.objSimp.isUQActivate() and hasattr(self,'checkBoxUQ') :
101 self.checkBoxUQ.setChecked(True)
105 nomTraduit=tr(self.objSimp.nom)
106 #metrix= QFontMetrics(self.label.font())
107 #maxLongueur = self.label.width() - 2
108 #print ('______________________')
110 #print (self.label.font().pixelSize())
111 #longueur2 = metrix.boundingRect(nomTraduit).width()
112 longueur=QFontMetrics(self.label.font()).width(nomTraduit)
113 if longueur >= nomMax :
114 nouveauNom=self.formate(nomTraduit)
115 self.label.setText(nouveauNom)
117 self.label.setText(nomTraduit)
118 #clidedText = metrics.elidedText(text, Qt.ElideRight, label.width());
119 #if (clippedText != nomTraduit): self.label.setToolTip(nomTraduit)
120 #self.label.setText(clippedText)
123 # inutile pour certains widgets
124 # if self.height() < 40 :
125 # self.setMinimumHeight(50)
126 # self.resize(self.width(),200)
128 #def mousePressEvent(self, event):
129 #print 'mousePressEvent'
131 #print (inspect.getmro(self.__class__))
132 #self.__class__.mousePressEvent(self, event)
136 def setValeurs(self):
137 # print "passe dans setValeurs pour ", self.objSimp.nom
138 # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
141 def finCommentaire(self):
145 def finCommentaireListe(self):
147 mc = self.node.item.get_definition()
148 d_aides = { 'TXM' : 'chaines de caracteres',
153 if not type in d_aides :
155 commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
158 commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
163 commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
164 elif mc.max == float('inf') :
165 commentaire=tr("Entrez une liste de ") +" "+tr(d_aides[type])+'\n'
167 commentaire=tr("Entrez entre ")+"\n"+str(mc.min)+(" et ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
168 aideval=self.node.item.aide()
169 commentaire=commentaire + tr(aideval)
170 return str(commentaire)
173 def setSuggestion(self):
174 if self.monSimpDef.getSug() != None and self.monSimpDef.getSug() != "":
175 suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.getSug())+"</span></p></body></html>"
176 if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
178 def setCommentaire(self):
179 c = self.debutToolTip
180 #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
182 if self.objSimp.getFr() != None and self.objSimp.getFr() != "":
183 #c2 = '<html><head/><body><p>'+c+self.objSimp.getFr().decode('latin-1','replace')+"</p></body></html>"
184 c2 = '<html><head/><body><p>'+c+self.objSimp.getFr()
185 #c2 = '<html><head/><body><p>'+c+self.objSimp.getFr()+"</p></body></html>"
186 self.label.setToolTip(c2)
187 #self.aide=self.objSimp.getFr().decode('latin-1','ignore')+" "+c
188 self.aide=self.objSimp.getFr()+" "+c
190 c+=self.finCommentaire()
191 if c != "" and c != None :
193 #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
194 c=str('<html><head/><body><p>')+c+"</p></body></html>"
195 self.label.setToolTip(c)
197 if self.editor.maConfiguration.differencieSiDefaut :
198 self.label.setToolTip('defaut : ' + tr(str(self.node.item.object.definition.defaut)))
202 def showEvent(self, event):
203 if self.prendLeFocus==1 :
204 self.activateWindow()
205 "il faut deriver le showEvent pour" , self.nom
207 QWidget.showEvent(self,event)
209 def aideALaSaisie(self):
210 mc = self.node.item.get_definition()
212 d_aides = { 'TXM' : tr(u"chaine de caracteres"),
215 'C' : tr("complexe"),
216 'Matrice' : tr(u'Matrice'),
217 'Fichier' : tr(u'fichier'),
218 'FichierNoAbs' : tr(u'fichier existant'),
219 'Repertoire' : tr(u'repertoire')}
221 if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
222 else : commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max) + " "
225 if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
226 else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
228 ctype = d_aides.get(mctype, tr("Type de base inconnu"))
229 if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
230 if ctype == tr("Type de base inconnu") and "bool" in str(mctype): ctype='bool'
233 if ctype == 'chaine de caractere' and mc.max>1 : ctype = 'chaines de caractere'
234 else : ctype = ctype + 's'
236 if mc.max!=1 : commentaire+="s"
239 def setZoneInfo(self):
240 # info=str(self.nom)+' '
241 # if self.monSimpDef.getFr() != None and self.monSimpDef.getFr() != "": info+=self.monSimpDef.getSug() +" "
242 # if self.monSimpDef.getSug() != None and self.monSimpDef.getSug() != "": info+="Valeur suggeree : "self.monSimpDef.getSug()
247 if self.editor.jdc.aReafficher==True :
248 self.parentQt.reaffiche()
250 #PN PN PN pas satisfaisant
251 #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
252 #print nodeAVoir.fenetre
253 #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
254 #if nodeAVoir.fenetre.isVisible() : return
255 #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
256 #nodeAVoir.fenetre.setFocus()
257 # return # on est bien postionne
259 if self.objSimp.isValid() and hasattr(self, 'AAfficher'):
260 nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
262 index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
263 if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
265 nodeAVoir.fenetre.setValeursApresBouton()
269 self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
273 if self.objSimp.isValid() and hasattr(self, 'AAfficher'):
275 self.setValeursApresBouton()
278 self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
280 if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
282 def reaffichePourDeplier(self):
283 self.parentQt.reaffiche()
285 def rendVisible(self):
288 #def enterEvent(self,event):
289 # print "je passe dans enterEvent", self.nom
290 # QWidget.enterEvent(self,event)
292 def traiteClicSurLabel(self,texte):
293 #aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
295 aide=self.aide+"\n"+self.aideALaSaisie()
297 aide=self.aideALaSaisie()
298 self.editor.afficheCommentaire(aide)
302 newText=t[0:l]+'-\n'+t[l:]