Salome HOME
version 19 mars
[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.setPoubelle()
67        self.setIcones()
68        self.setCommentaire()
69        self.setZoneInfo()
70           
71
72    def setNom(self):
73        self.debutToolTip=""
74        nomTraduit=tr(self.objSimp.nom)
75        if len(nomTraduit) >= nomMax :
76          nom=nomTraduit[0:nomMax]+'...'
77          self.label.setText(nomTraduit)
78          self.debutToolTip=nomTraduit+"\n"
79        else :   
80          self.label.setText(nomTraduit)
81
82                                  
83    def setValeurs(self):
84       # print "passe dans setValeurs pour ", self.objSimp.nom
85       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
86         pass
87
88    def finCommentaire(self):
89        return ""
90
91    def setSuggestion(self):
92       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
93          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
94          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
95
96    def setCommentaire(self):
97       c  = self.debutToolTip
98       if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
99       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
100           c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
101           self.label.setToolTip(c2)
102       else :
103          c+=self.finCommentaire()
104          if c != "" and c != None :
105             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
106             c=str('<html><head/><body><p>')+c+"</p></body></html>"
107             self.label.setToolTip(c)
108
109    def setIcones(self):
110
111        mctype = self.monSimpDef.type[0]
112        # selon 
113        if ( hasattr(self,"BFichier")): 
114           if mctype == "Repertoire":
115              self.BRepertoire=self.BFichier
116              self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
117           else :
118              #icon = QIcon(self.repIcon+"/visuFichier.png")
119              self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
120              self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
121           return
122
123        if ( hasattr(self,"BSalome")): 
124           enable_salome_selection = self.editor.salome and \
125               (('grma' in repr(mctype)) or ('grno' in repr(mctype)) or ('SalomeEntry' in repr(mctype)) or
126                (hasattr(mctype, "enable_salome_selection") and mctype.enable_salome_selection))
127           if  enable_salome_selection:
128               self.connect(self.BSalome,SIGNAL("pressed()"),self.BSalomePressed)
129
130               if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome):
131                 self.BView2D.close()
132               else :
133                 self.connect(self.BView2D,SIGNAL("clicked()"),self.BView2DPressed)
134           else:
135               self.BSalome.close()
136               self.BView2D.close()
137
138
139    def showEvent(self, event):
140       if self.prendLeFocus==1 :
141          self.activateWindow()
142          "il faut deriver le showEvent pour" , self.nom
143          self.prendLeFocus=0
144       QWidget.showEvent(self,event)
145
146    def aideALaSaisie(self):
147       return
148       mc = self.node.item.get_definition()
149       mctype = mc.type[0]
150       d_aide = { 'TXM' : tr(u"chaine de caracteres"),
151                   'R'   : tr("reel"),
152                   'I'   : tr("entier"),
153                   'C'   : tr("complexe"),
154                   'Matrice' : tr(u'Matrice'),
155                   'Fichier' : tr(u'fichier'),
156                   'FichierNoAbs' : tr(u'fichier existant'),
157                   'Repertoire' : tr(u'repertoire')}
158       if mc.min == mc.max: commentaire=tr("Entrez ")+str(mc.min)
159       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
160
161       if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
162       else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
163       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
164
165       commentaire+=ctype
166       if self.max!=1 : commentaire+="s" 
167       return commentaire
168
169    def setZoneInfo(self):
170       # info=str(self.nom)+'  '
171       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
172       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
173       pass
174       #self.editor.affiche_infos(info)
175
176    def reaffiche(self):
177       print "dans reaffiche de feuille", self.nom
178       if self.editor.jdc.aReafficher==True :
179          print " j appelle le reaffiche de parentQt"
180          self.parentQt.reaffiche()
181          #PN PN PN pas satisfaisant
182          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
183          #print nodeAVoir.fenetre
184          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
185          #if nodeAVoir.fenetre.isVisible() : return
186          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
187          #nodeAVoir.fenetre.setFocus()
188