Salome HOME
Pour V1 Carmel
[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=26
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        else :   
81          self.label.setText(nomTraduit)
82
83                                  
84    def setValeurs(self):
85       # print "passe dans setValeurs pour ", self.objSimp.nom
86       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
87         pass
88
89    def finCommentaire(self):
90        return ""
91
92    def setSuggestion(self):
93       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
94          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
95          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
96
97    def setCommentaire(self):
98       c  = self.debutToolTip
99       if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
100       self.aide=c
101       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
102           c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
103           self.label.setToolTip(c2)
104           self.aide=str(self.objSimp.get_fr())+" "+c
105       else :
106          c+=self.finCommentaire()
107          if c != "" and c != None :
108             self.aide=c
109             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
110             c=str('<html><head/><body><p>')+c+"</p></body></html>"
111             self.label.setToolTip(c)
112
113
114
115    def showEvent(self, event):
116       if self.prendLeFocus==1 :
117          self.activateWindow()
118          "il faut deriver le showEvent pour" , self.nom
119          self.prendLeFocus=0
120       QWidget.showEvent(self,event)
121
122    def aideALaSaisie(self):
123       mc = self.node.item.get_definition()
124       mctype = mc.type[0]
125       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
126                   'R'   : tr("reel"),
127                   'I'   : tr("entier"),
128                   'C'   : tr("complexe"),
129                   'Matrice' : tr(u'Matrice'),
130                   'Fichier' : tr(u'fichier'),
131                   'FichierNoAbs' : tr(u'fichier existant'),
132                   'Repertoire' : tr(u'repertoire')}
133
134       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
135       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
136
137       if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
138       else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
139       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
140
141       commentaire+=ctype
142       if mc.max!=1 : commentaire+="s" 
143       return commentaire
144
145    def setZoneInfo(self):
146       # info=str(self.nom)+'  '
147       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
148       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
149       pass
150       #self.editor.affiche_infos(info)
151
152    def reaffiche(self):
153       #print "dans reaffiche de feuille", self.nom
154       if self.editor.jdc.aReafficher==True :
155          #print " j appelle le reaffiche de parentQt"
156          self.parentQt.reaffiche()
157
158          #PN PN PN pas satisfaisant
159          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
160          #print nodeAVoir.fenetre
161          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
162          #if nodeAVoir.fenetre.isVisible() : return
163          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
164          #nodeAVoir.fenetre.setFocus()
165          # return  # on est bien postionne
166       if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
167          self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
168       else :
169          print "dans le else de reaffiche"
170          self.AAfficher.setFocus(7)
171
172
173    def traiteClicSurLabel(self,texte):
174        #print self.aide 
175        self.aide+="\n"+self.aideALaSaisie()
176        self.editor.affiche_infos(self.aide)