Salome HOME
sauve du 9 mai
[tools/eficas.git] / InterfaceQT4 / feuille.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   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 import string,types,os
22 import traceback
23
24 from determine import monEnvQT5
25 if monEnvQT5:
26    from PyQt5.QtWidgets import QToolButton ,QWidget
27    from PyQt5.QtGui import QFont, QFontMetrics
28 else :
29    from PyQt4.QtGui import *
30    from PyQt4.QtCore import *
31 from Extensions.i18n import tr
32
33
34 from gereIcones import ContientIcones
35 from gereIcones import FacultatifOuOptionnel
36 from qtSaisie    import SaisieValeur
37
38 nomMax=250
39 # ---------------------------------------------------------------------- #
40 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
41 # --------------------------------------------------------------------- #
42
43
44    def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
45        #print "Feuille", monSimpDef,nom,objSimp
46        #print self
47        QWidget.__init__(self,None)
48        self.node=node
49        self.node.fenetre=self
50
51        # on se positionne pour les icones
52        #os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__))))
53        self.setupUi(self)
54        self.prendLeFocus=0
55
56        maPolice= QFont("Times", 10)
57        self.setFont(maPolice)
58
59        self.parentQt=parentQt
60        self.editor=self.node.editor
61        self.appliEficas=self.editor.appliEficas
62        self.repIcon=self.appliEficas.repIcon
63        self.monSimpDef=monSimpDef
64        self.nom=nom
65        self.objSimp=objSimp
66        self.node.fenetre=self
67        self.maCommande=commande
68
69        self.aRedimensionner=0
70        self.setSuggestion()
71        self.setValeurs()
72        self.setNom()
73        self.setValide()
74        self.setIconePoubelle()
75        self.setIconesFichier()
76        self.setIconesSalome()
77        self.setIconesGenerales()
78        self.setCommentaire()
79        self.setZoneInfo()
80           
81
82    def setNom(self):
83        self.debutToolTip=""
84        nomTraduit=tr(self.objSimp.nom)
85        #if len(nomTraduit) >= nomMax :
86        #  nom=nomTraduit[0:nomMax]+'...'
87        #  self.label.setText(nomTraduit)
88        #  self.debutToolTip=nomTraduit+"\n"
89        longueur=QFontMetrics(self.label.font()).width(nomTraduit)
90        if longueur >= nomMax :
91          nouveauNom=self.formate(nomTraduit)
92          self.label.setText(nouveauNom)
93        else :   
94          self.label.setText(nomTraduit)
95
96    def agrandit(self):
97        # inutile pour certains widgets
98        if self.height() < 40 :
99           self.setMinimumHeight(50)
100           self.resize(self.width(),200)
101
102                                  
103    def setValeurs(self):
104       # print "passe dans setValeurs pour ", self.objSimp.nom
105       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
106         pass
107
108    def finCommentaire(self):
109        return ""
110
111    
112    def finCommentaireListe(self):
113         commentaire=""
114         mc = self.node.item.get_definition()
115         d_aides = { 'TXM' : 'chaines de caracteres',
116                   'R'   : 'reels',
117                   'I'   : 'entiers',
118                   'C'   : 'complexes'}
119         type = mc.type[0]
120         if not d_aides.has_key(type) :
121            if mc.min == mc.max:
122                commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
123            else :
124                commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
125         else :
126            if mc.min == mc.max:
127                commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
128            else :
129                commentaire=tr("Entrez entre ")+str(mc.min)+(" et  ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
130         aideval=self.node.item.aide()
131         commentaire=commentaire +  tr(aideval)
132         self.monCommentaireLabel.setText(str(commentaire))
133         return str(commentaire)
134
135
136    def setSuggestion(self):
137       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
138          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
139          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
140
141    def setCommentaire(self):
142       c  = self.debutToolTip
143       #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
144       self.aide=c
145       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
146           c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
147           self.label.setToolTip(c2)
148           self.aide=str(self.objSimp.get_fr())+" "+c
149       else :
150          c+=self.finCommentaire()
151          if c != "" and c != None :
152             self.aide=c
153             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
154             c=str('<html><head/><body><p>')+c+"</p></body></html>"
155             self.label.setToolTip(c)
156
157
158
159    def showEvent(self, event):
160       if self.prendLeFocus==1 :
161          self.activateWindow()
162          "il faut deriver le showEvent pour" , self.nom
163          self.prendLeFocus=0
164       QWidget.showEvent(self,event)
165
166    def aideALaSaisie(self):
167       mc = self.node.item.get_definition()
168       mctype = mc.type[0]
169       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
170                   'R'   : tr("reel"),
171                   'I'   : tr("entier"),
172                   'C'   : tr("complexe"),
173                   'Matrice' : tr(u'Matrice'),
174                   'Fichier' : tr(u'fichier'),
175                   'FichierNoAbs' : tr(u'fichier existant'),
176                   'Repertoire' : tr(u'repertoire')}
177
178       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
179       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
180
181       if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
182       else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
183       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
184
185       commentaire+=ctype
186       if mc.max!=1 : commentaire+="s" 
187       return commentaire
188
189    def setZoneInfo(self):
190       # info=str(self.nom)+'  '
191       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
192       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
193       pass
194       #self.editor.affiche_infos(info)
195
196    def reaffiche(self):
197       #print "dans reaffiche de feuille", self.nom
198       if self.editor.jdc.aReafficher==True :
199          self.parentQt.reaffiche()
200
201          #PN PN PN pas satisfaisant
202          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
203          #print nodeAVoir.fenetre
204          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
205          #if nodeAVoir.fenetre.isVisible() : return
206          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
207          #nodeAVoir.fenetre.setFocus()
208          # return  # on est bien postionne
209
210          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
211             nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
212             try :
213                index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
214                if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
215                   try :
216                      nodeAVoir.fenetre.setValeursApresBouton()
217                   except :
218                      pass
219                else :
220                   self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
221             except :
222                pass
223       else :
224          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
225             try :
226                self.setValeursApresBouton()
227             except :
228                self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
229          else :
230             if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
231
232    def reaffichePourDeplier(self):
233       self.parentQt.reaffiche()
234
235    def rendVisible(self):
236        #print "jjjjjjjjjjjjjjjjjjjjj"
237        pass
238
239    def traiteClicSurLabel(self,texte):
240        #print self.aide 
241        aide=self.aide+"\n"+self.aideALaSaisie()
242        self.editor.affiche_commentaire(aide)
243
244    def formate(self,t):
245        if t.find('_')==0 :
246           newText=t[0:19]+'\n'+t[19:]
247        else:
248           listeNom=t.split('_')
249           newTexte=""
250           ligne=""
251           for n in listeNom:
252             if len(ligne)+len(n) < 25 : 
253                newTexte=newTexte+"_"+n
254                ligne+="_"+n
255             else :
256                newTexte=newTexte+"\n_"+n
257                ligne=""
258           #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
259           newText=newTexte[1:]
260        return newText
261       
262
263