Salome HOME
linux/windows
[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 PyQt4 import *
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 from Extensions.i18n import tr
28
29 from gereIcones import ContientIcones
30 from gereIcones import FacultatifOuOptionnel
31 from qtSaisie    import SaisieValeur
32
33 nomMax=250
34 # ---------------------------------------------------------------------- #
35 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
36 # --------------------------------------------------------------------- #
37
38
39    def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
40        #print "Feuille", monSimpDef,nom,objSimp
41        #print self
42        QWidget.__init__(self,None)
43        self.node=node
44        self.node.fenetre=self
45        self.setupUi(self)
46        self.prendLeFocus=0
47
48        maPolice= QFont("Times", 10)
49        self.setFont(maPolice)
50
51        self.parentQt=parentQt
52        self.editor=self.node.editor
53        self.appliEficas=self.editor.appliEficas
54        self.repIcon=self.appliEficas.repIcon
55        self.monSimpDef=monSimpDef
56        self.nom=nom
57        self.objSimp=objSimp
58        self.node.fenetre=self
59        self.maCommande=commande
60
61        self.aRedimensionner=0
62        self.setSuggestion()
63        self.setValeurs()
64        self.setNom()
65        self.setValide()
66        self.setIconePoubelle()
67        self.setIconesFichier()
68        self.setIconesSalome()
69        self.setCommentaire()
70        self.setZoneInfo()
71           
72
73    def setNom(self):
74        self.debutToolTip=""
75        nomTraduit=tr(self.objSimp.nom)
76        #if len(nomTraduit) >= nomMax :
77        #  nom=nomTraduit[0:nomMax]+'...'
78        #  self.label.setText(nomTraduit)
79        #  self.debutToolTip=nomTraduit+"\n"
80        longueur=QFontMetrics(self.label.font()).width(nomTraduit)
81        if longueur >= nomMax :
82          nouveauNom=self.formate(nomTraduit)
83          self.label.setText(nouveauNom)
84        else :   
85          self.label.setText(nomTraduit)
86
87    def agrandit(self):
88        # inutile pour certains widgets
89        if self.height() < 40 :
90           self.setMinimumHeight(50)
91           self.resize(self.width(),200)
92
93                                  
94    def setValeurs(self):
95       # print "passe dans setValeurs pour ", self.objSimp.nom
96       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
97         pass
98
99    def finCommentaire(self):
100        return ""
101
102    def setSuggestion(self):
103       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
104          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
105          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
106
107    def setCommentaire(self):
108       c  = self.debutToolTip
109       #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
110       self.aide=c
111       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
112           c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
113           self.label.setToolTip(c2)
114           self.aide=str(self.objSimp.get_fr())+" "+c
115       else :
116          c+=self.finCommentaire()
117          if c != "" and c != None :
118             self.aide=c
119             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
120             c=str('<html><head/><body><p>')+c+"</p></body></html>"
121             self.label.setToolTip(c)
122
123
124
125    def showEvent(self, event):
126       if self.prendLeFocus==1 :
127          self.activateWindow()
128          "il faut deriver le showEvent pour" , self.nom
129          self.prendLeFocus=0
130       QWidget.showEvent(self,event)
131
132    def aideALaSaisie(self):
133       mc = self.node.item.get_definition()
134       mctype = mc.type[0]
135       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
136                   'R'   : tr("reel"),
137                   'I'   : tr("entier"),
138                   'C'   : tr("complexe"),
139                   'Matrice' : tr(u'Matrice'),
140                   'Fichier' : tr(u'fichier'),
141                   'FichierNoAbs' : tr(u'fichier existant'),
142                   'Repertoire' : tr(u'repertoire')}
143
144       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
145       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
146
147       if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
148       else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
149       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
150
151       commentaire+=ctype
152       if mc.max!=1 : commentaire+="s" 
153       return commentaire
154
155    def setZoneInfo(self):
156       # info=str(self.nom)+'  '
157       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
158       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
159       pass
160       #self.editor.affiche_infos(info)
161
162    def reaffiche(self):
163       #print "dans reaffiche de feuille", self.nom
164       if self.editor.jdc.aReafficher==True :
165          #print " j appelle le reaffiche de parentQt"
166          self.parentQt.reaffiche()
167
168          #PN PN PN pas satisfaisant
169          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
170          #print nodeAVoir.fenetre
171          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
172          #if nodeAVoir.fenetre.isVisible() : return
173          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
174          #nodeAVoir.fenetre.setFocus()
175          # return  # on est bien postionne
176       if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
177          self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
178       else :
179          if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
180
181
182    def traiteClicSurLabel(self,texte):
183        #print self.aide 
184        aide=self.aide+"\n"+self.aideALaSaisie()
185        self.editor.affiche_infos(aide)
186
187    def formate(self,t):
188        if t.find('_')==0 :
189           newText=t[0:19]+'\n'+t[19:]
190        else:
191           listeNom=t.split('_')
192           newTexte=""
193           ligne=""
194           for n in listeNom:
195             if len(ligne)+len(n) < 25 : 
196                newTexte=newTexte+"_"+n
197                ligne+="_"+n
198             else :
199                newTexte=newTexte+"\n_"+n
200                ligne=""
201           #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
202           newText=newTexte[1:]
203        return newText
204       
205
206