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