Salome HOME
ae30044f8b40b2cee22b1b22528a01f0f1730870
[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                if mc.max != "**" :
130                   commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
131                else :
132                   commentaire=""
133         else :
134            if mc.min == mc.max:
135                commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
136            else :
137                commentaire=tr("Entrez entre ")+str(mc.min)+(" et  ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
138         aideval=self.node.item.aide()
139         commentaire=commentaire +  tr(aideval)
140         self.monCommentaireLabel.setText(str(commentaire))
141         return str(commentaire)
142
143
144    def setSuggestion(self):
145       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
146          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
147          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
148
149    def setCommentaire(self):
150       c  = self.debutToolTip
151       #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
152       self.aide=c
153       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
154           c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
155           self.label.setToolTip(c2)
156           self.aide=str(self.objSimp.get_fr())+" "+c
157       else :
158          c+=self.finCommentaire()
159          if c != "" and c != None :
160             self.aide=c
161             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
162             c=str('<html><head/><body><p>')+c+"</p></body></html>"
163             self.label.setToolTip(c)
164
165
166
167    def showEvent(self, event):
168       if self.prendLeFocus==1 :
169          self.activateWindow()
170          "il faut deriver le showEvent pour" , self.nom
171          self.prendLeFocus=0
172       QWidget.showEvent(self,event)
173
174    def aideALaSaisie(self):
175       mc = self.node.item.get_definition()
176       mctype = mc.type[0]
177       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
178                   'R'   : tr("reel"),
179                   'I'   : tr("entier"),
180                   'C'   : tr("complexe"),
181                   'Matrice' : tr(u'Matrice'),
182                   'Fichier' : tr(u'fichier'),
183                   'FichierNoAbs' : tr(u'fichier existant'),
184                   'Repertoire' : tr(u'repertoire')}
185
186       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
187       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
188
189       if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
190       else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
191       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
192
193       commentaire+=ctype
194       if mc.max!=1 : commentaire+="s" 
195       return commentaire
196
197    def setZoneInfo(self):
198       # info=str(self.nom)+'  '
199       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
200       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
201       pass
202
203    def reaffiche(self):
204       #print "dans reaffiche de feuille", self.nom
205       if self.editor.jdc.aReafficher==True :
206          self.parentQt.reaffiche()
207
208          #PN PN PN pas satisfaisant
209          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
210          #print nodeAVoir.fenetre
211          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
212          #if nodeAVoir.fenetre.isVisible() : return
213          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
214          #nodeAVoir.fenetre.setFocus()
215          # return  # on est bien postionne
216
217          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
218             nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
219             try :
220                index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
221                if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
222                   try :
223                      nodeAVoir.fenetre.setValeursApresBouton()
224                   except :
225                      pass
226                else :
227                   self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
228             except :
229                pass
230       else :
231          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
232             try :
233                self.setValeursApresBouton()
234             except :
235                self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
236          else :
237             if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
238
239    def reaffichePourDeplier(self):
240       self.parentQt.reaffiche()
241
242    def rendVisible(self):
243        #print "jjjjjjjjjjjjjjjjjjjjj"
244        pass
245
246    #def enterEvent(self,event):
247    #   print "je passe dans enterEvent", self.nom
248    #   QWidget.enterEvent(self,event)
249
250    def traiteClicSurLabel(self,texte):
251        #print self.aide 
252        aide=self.aide+"\n"+self.aideALaSaisie()
253        self.editor.affiche_commentaire(aide)
254
255    def formate(self,t):
256        if t.find('_')==0 :
257           newText=t[0:19]+'\n'+t[19:]
258        else:
259           listeNom=t.split('_')
260           newTexte=""
261           ligne=""
262           for n in listeNom:
263             if len(ligne)+len(n) < 25 : 
264                newTexte=newTexte+"_"+n
265                ligne+="_"+n
266             else :
267                newTexte=newTexte+"\n_"+n
268                ligne=""
269           #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
270           newText=newTexte[1:]
271        return newText
272       
273
274