Salome HOME
aa6f6e0945e4d5a52121b7a7ffb21fa717dea35a
[tools/eficas.git] / InterfaceQT4 / feuille.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Modules Python
21 from __future__ import absolute_import
22 try :
23   from builtins import str
24 except :
25   pass
26 import types,os
27 import traceback
28
29 from PyQt5.QtWidgets import QToolButton ,QWidget
30 from PyQt5.QtGui import QFont, QFontMetrics, QFontInfo, QPalette
31 from PyQt5.QtCore import Qt
32
33 from Extensions.i18n import tr
34
35 from .gereIcones import ContientIcones
36 from .gereIcones import FacultatifOuOptionnel
37 from .qtSaisie    import SaisieValeur
38
39 nomMax=230
40 # empirique les metrics ne fonctionnent pas 
41 # ---------------------------------------------------------------------- #
42 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
43 # --------------------------------------------------------------------- #
44
45
46    def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
47        #print ("Feuille", monSimpDef,nom,objSimp)
48        QWidget.__init__(self,None)
49        self.node=node
50        self.node.fenetre=self
51
52        # on se positionne pour les icones
53        #os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__))))
54        self.setupUi(self)
55        self.prendLeFocus=0
56
57        maPolice= QFont("Times", 10)
58        self.setFont(maPolice)
59        self.setFocusPolicy(Qt.StrongFocus)
60
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
66        self.nom=nom
67        self.objSimp=objSimp
68        self.node.fenetre=self
69        self.maCommande=commande
70
71        self.aRedimensionner=0
72        self.setSuggestion()
73        self.setValeurs()
74        self.setNom()
75        self.setValide()
76        self.setIconePoubelle()
77        self.setIconesFichier()
78        self.setIconesSalome()
79        self.setIconesGenerales()
80        self.setCommentaire()
81        self.setZoneInfo()
82      
83
84    def setNom(self):
85        self.debutToolTip=""
86        nomTraduit=tr(self.objSimp.nom)
87        #metrix= QFontMetrics(self.label.font())
88        #maxLongueur = self.label.width() - 2
89        #print ('______________________')
90        #print (nomTraduit)
91        #print (self.label.font().pixelSize())
92        #longueur2 = metrix.boundingRect(nomTraduit).width()
93        longueur=QFontMetrics(self.label.font()).width(nomTraduit)
94        if longueur >= nomMax :
95          nouveauNom=self.formate(nomTraduit)
96          self.label.setText(nouveauNom)
97        else :   
98          self.label.setText(nomTraduit)
99        #clidedText = metrics.elidedText(text, Qt.ElideRight, label.width());
100        #if (clippedText != nomTraduit): self.label.setToolTip(nomTraduit)
101        #self.label.setText(clippedText)
102
103    #def agrandit(self):
104        # inutile pour certains widgets
105    #    if self.height() < 40 :
106    #       self.setMinimumHeight(50)
107    #       self.resize(self.width(),200)
108
109    #def mousePressEvent(self, event):
110      #print 'mousePressEvent'
111      #import inspect
112      #print (inspect.getmro(self.__class__))
113      #self.__class__.mousePressEvent(self, event)
114
115
116                                  
117    def setValeurs(self):
118       # print "passe dans setValeurs pour ", self.objSimp.nom
119       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
120         pass
121
122    def finCommentaire(self):
123        return ""
124
125    
126    def finCommentaireListe(self):
127         commentaire=""
128         mc = self.node.item.get_definition()
129         d_aides = { 'TXM' : 'chaines de caracteres',
130                   'R'   : 'reels',
131                   'I'   : 'entiers',
132                   'C'   : 'complexes'}
133         type = mc.type[0]
134         if not type in d_aides :
135            if mc.min == mc.max:
136                commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
137            else :
138                if mc.max != "**" :
139                   commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
140                else :
141                   commentaire=""
142         else :
143            if mc.min == mc.max:
144                commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
145            elif mc.max == float('inf') :
146                commentaire=tr("Entrez une liste de ") + tr(d_aides[type])+'\n'
147            else :
148                commentaire=tr("Entrez entre ")+"\n"+str(mc.min)+(" et  ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
149         aideval=self.node.item.aide()
150         commentaire=commentaire +  tr(aideval)
151         return str(commentaire)
152
153
154    def setSuggestion(self):
155       if self.monSimpDef.getSug() != None and self.monSimpDef.getSug() != "":
156          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.getSug())+"</span></p></body></html>"
157          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
158
159    def setCommentaire(self):
160       c  = self.debutToolTip
161       #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
162       self.aide=c
163       if self.objSimp.getFr() != None and self.objSimp.getFr() != "":
164           #c2 = '<html><head/><body><p>'+c+self.objSimp.getFr().decode('latin-1','replace')+"</p></body></html>"
165           c2 = '<html><head/><body><p>'+c+self.objSimp.getFr()
166           #c2 = '<html><head/><body><p>'+c+self.objSimp.getFr()+"</p></body></html>"
167           self.label.setToolTip(c2)
168           #self.aide=self.objSimp.getFr().decode('latin-1','ignore')+" "+c
169           self.aide=self.objSimp.getFr()+" "+c
170       else :
171          c+=self.finCommentaire()
172          if c != "" and c != None :
173             self.aide=c
174             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
175             c=str('<html><head/><body><p>')+c+"</p></body></html>"
176             self.label.setToolTip(c)
177
178       if self.editor.maConfiguration.differencieSiDefaut :
179             self.label.setToolTip('defaut : ' + tr(str(self.node.item.object.definition.defaut)))
180
181
182
183    def showEvent(self, event):
184       if self.prendLeFocus==1 :
185          self.activateWindow()
186          "il faut deriver le showEvent pour" , self.nom
187          self.prendLeFocus=0
188       QWidget.showEvent(self,event)
189
190    def aideALaSaisie(self):
191       mc = self.node.item.get_definition()
192       mctype = mc.type[0]
193       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
194                   'R'   : tr("reel"),
195                   'I'   : tr("entier"),
196                   'C'   : tr("complexe"),
197                   'Matrice' : tr(u'Matrice'),
198                   'Fichier' : tr(u'fichier'),
199                   'FichierNoAbs' : tr(u'fichier existant'),
200                   'Repertoire' : tr(u'repertoire')}
201
202       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
203       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
204
205       try :
206          if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
207          else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
208       except:                        
209          ctype = d_aides.get(mctype, tr("Type de base inconnu"))
210       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
211
212       commentaire+=ctype
213       if mc.max!=1 : commentaire+="s" 
214       return commentaire
215
216    def setZoneInfo(self):
217       # info=str(self.nom)+'  '
218       # if self.monSimpDef.getFr() != None and self.monSimpDef.getFr() != "": info+=self.monSimpDef.getSug() +" "
219       # if self.monSimpDef.getSug() != None and self.monSimpDef.getSug() != "": info+="Valeur suggeree : "self.monSimpDef.getSug()
220       pass
221
222    def reaffiche(self):
223
224       if self.editor.jdc.aReafficher==True :
225          self.parentQt.reaffiche()
226
227          #PN PN PN pas satisfaisant
228          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
229          #print nodeAVoir.fenetre
230          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
231          #if nodeAVoir.fenetre.isVisible() : return
232          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
233          #nodeAVoir.fenetre.setFocus()
234          # return  # on est bien postionne
235
236          if self.objSimp.isValid() and hasattr(self, 'AAfficher'):
237             nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
238             try :
239                index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
240                if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
241                   try :
242                      nodeAVoir.fenetre.setValeursApresBouton()
243                   except :
244                      pass
245                else :
246                   self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
247             except :
248                pass
249       else :
250          if self.objSimp.isValid() and hasattr(self, 'AAfficher'):
251             try :
252                self.setValeursApresBouton()
253             except :
254                pass
255             self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
256          else :
257             if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
258
259    def reaffichePourDeplier(self):
260       self.parentQt.reaffiche()
261
262    def rendVisible(self):
263        pass
264
265    #def enterEvent(self,event):
266    #   print "je passe dans enterEvent", self.nom
267    #   QWidget.enterEvent(self,event)
268
269    def traiteClicSurLabel(self,texte):
270        #aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
271        try :
272           aide=self.aide+"\n"+self.aideALaSaisie()
273        except :
274           aide=self.aideALaSaisie()
275        self.editor.afficheCommentaire(aide)
276
277    def formate(self,t):
278        l=len(t)//2
279        newText=t[0:l]+'-\n'+t[l:]
280        return newText
281       
282
283