Salome HOME
961c41950d681d4cf44ce8b78b3aea55e6c13584
[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    from PyQt5.QtCore import Qt
29 else :
30    from PyQt4.QtGui import *
31    from PyQt4.QtCore import *
32 from Extensions.i18n import tr
33
34
35 from gereIcones import ContientIcones
36 from gereIcones import FacultatifOuOptionnel
37 from qtSaisie    import SaisieValeur
38
39 nomMax=250
40 # ---------------------------------------------------------------------- #
41 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
42 # --------------------------------------------------------------------- #
43
44
45    def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
46        #print "Feuille", monSimpDef,nom,objSimp
47        #print self
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        print "kkkkkkkkkkkkkkkkkk"
87        print self.objSimp.nom
88        nomTraduit=tr(self.objSimp.nom)
89        print nomTraduit
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)
98        else :   
99          self.label.setText(nomTraduit)
100
101    def agrandit(self):
102        # inutile pour certains widgets
103        if self.height() < 40 :
104           self.setMinimumHeight(50)
105           self.resize(self.width(),200)
106
107                                  
108    def setValeurs(self):
109       # print "passe dans setValeurs pour ", self.objSimp.nom
110       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
111         pass
112
113    def finCommentaire(self):
114        return ""
115
116    
117    def finCommentaireListe(self):
118         commentaire=""
119         mc = self.node.item.get_definition()
120         d_aides = { 'TXM' : 'chaines de caracteres',
121                   'R'   : 'reels',
122                   'I'   : 'entiers',
123                   'C'   : 'complexes'}
124         type = mc.type[0]
125         if not d_aides.has_key(type) :
126            if mc.min == mc.max:
127                commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
128            else :
129                commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
130         else :
131            if mc.min == mc.max:
132                commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
133            else :
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)
139
140
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)
145
146    def setCommentaire(self):
147       c  = self.debutToolTip
148       #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
149       self.aide=c
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
154       else :
155          c+=self.finCommentaire()
156          if c != "" and c != None :
157             self.aide=c
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)
161
162
163
164    def showEvent(self, event):
165       if self.prendLeFocus==1 :
166          self.activateWindow()
167          "il faut deriver le showEvent pour" , self.nom
168          self.prendLeFocus=0
169       QWidget.showEvent(self,event)
170
171    def aideALaSaisie(self):
172       mc = self.node.item.get_definition()
173       mctype = mc.type[0]
174       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
175                   'R'   : tr("reel"),
176                   'I'   : tr("entier"),
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')}
182
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)
185
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)
189
190       commentaire+=ctype
191       if mc.max!=1 : commentaire+="s" 
192       return commentaire
193
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()
198       pass
199       #self.editor.affiche_infos(info)
200
201    def reaffiche(self):
202       #print "dans reaffiche de feuille", self.nom
203       if self.editor.jdc.aReafficher==True :
204          self.parentQt.reaffiche()
205
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
214
215          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
216             nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
217             try :
218                index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
219                if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
220                   try :
221                      nodeAVoir.fenetre.setValeursApresBouton()
222                   except :
223                      pass
224                else :
225                   self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
226             except :
227                pass
228       else :
229          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
230             try :
231                self.setValeursApresBouton()
232             except :
233                self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
234          else :
235             if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
236
237    def reaffichePourDeplier(self):
238       self.parentQt.reaffiche()
239
240    def rendVisible(self):
241        #print "jjjjjjjjjjjjjjjjjjjjj"
242        pass
243
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)
248
249    def traiteClicSurLabel(self,texte):
250        #print self.aide 
251        aide=self.aide+"\n"+self.aideALaSaisie()
252        self.editor.affiche_commentaire(aide)
253
254    def formate(self,t):
255        if t.find('_')==0 :
256           newText=t[0:19]+'\n'+t[19:]
257        else:
258           listeNom=t.split('_')
259           newTexte=""
260           ligne=""
261           for n in listeNom:
262             if len(ligne)+len(n) < 25 : 
263                newTexte=newTexte+"_"+n
264                ligne+="_"+n
265             else :
266                newTexte=newTexte+"\n_"+n
267                ligne=""
268           #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
269           newText=newTexte[1:]
270        return newText
271       
272
273