Salome HOME
premiere version
[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 # ---------------------------------------------------------------------- #
34 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
35 # --------------------------------------------------------------------- #
36
37
38    def __init__(self,node,monSimpDef,nom,objSimp,parentQt):
39        #print "Feuille", monSimpDef,nom,objSimp
40        QWidget.__init__(self,None)
41        self.node=node
42        self.node.fenetre=self
43        self.setupUi(self)
44        self.prendLeFocus=0
45
46        maPolice= QFont("Times", 10)
47        self.setFont(maPolice)
48
49        self.parentQt=parentQt
50        self.editor=self.node.editor
51        self.appliEficas=self.editor.appliEficas
52        self.repIcon=self.appliEficas.repIcon
53        self.monSimpDef=monSimpDef
54        self.nom=nom
55        self.objSimp=objSimp
56        self.node.fenetre=self
57
58        self.aRedimensionner=0
59        self.setSuggestion()
60        self.setValeurs()
61        self.setNom()
62        self.setValide()
63        self.setPoubelle()
64        self.setIcones()
65        self.setCommentaire()
66        self.setZoneInfo()
67           
68
69    def setNom(self):
70        self.debutToolTip=""
71        if len(self.objSimp.nom) >= 17 :
72          nom=self.objSimp.nom[0:15]+'...'
73          self.label.setText(nom)
74          self.debutToolTip=self.objSimp.nom+"\n"
75        else :   
76          self.label.setText(self.objSimp.nom)
77
78                                  
79    def setValeurs(self):
80       # print "passe dans setValeurs pour ", self.objSimp.nom
81       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
82         pass
83
84    def finCommentaire(self):
85        return ""
86
87    def setSuggestion(self):
88       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
89          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
90          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
91
92    def setCommentaire(self):
93       #print "dans setCommentaire"
94      
95       c  = self.debutToolTip
96       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
97           c2 = '<html><head/><body><p><span style=" font-size:8pt;">'+c+str(self.objSimp.get_fr())+"</span></p></body></html>"
98           self.label.setToolTip(c2)
99       else :
100          c+=self.finCommentaire()
101          if c != "" and c != None :
102             c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
103             self.label.setToolTip(c)
104
105    def setIcones(self):
106
107        mctype = self.monSimpDef.type[0]
108        # selon 
109        if ( hasattr(self,"BFichier")): 
110           if mctype == "Repertoire":
111              self.BRepertoire=self.BFichier
112              #icon = QIcon(self.repIcon+"/fichier.png")
113              #self.BRepertoire.setIcon(icon)
114              self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
115              #self.BVisuFichier.close()
116           else :
117              #icon = QIcon(self.repIcon+"/visuFichier.png")
118              #self.BVisuFichier.setIcon(icon)
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               #icon = QIcon(self.repIcon+"/flecheSalome.png")
130               #self.BSalome.setIcon(icon)
131
132               if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome):
133                 self.BView2D.close()
134               else :
135                 #icon = QIcon(self.repIcon+"/salomeLoupe.png")
136                 #self.BView2D.setIcon(icon)
137                 self.connect(self.BView2D,SIGNAL("clicked()"),self.BView2DPressed)
138           else:
139               self.BSalome.close()
140               self.BView2D.close()
141
142
143    def showEvent(self, event):
144       if self.prendLeFocus==1 :
145          self.activateWindow()
146          "il faut deriver le showEvent pour" , self.nom
147          self.prendLeFocus=0
148       QWidget.showEvent(self,event)
149
150    def aideALaSaisie(self):
151       return
152       mc = self.node.item.get_definition()
153       mctype = mc.type[0]
154       d_aide = { 'TXM' : tr(u"chaine de caracteres"),
155                   'R'   : tr("reel"),
156                   'I'   : tr("entier"),
157                   'C'   : tr("complexe"),
158                   'Matrice' : tr(u'Matrice'),
159                   'Fichier' : tr(u'fichier'),
160                   'FichierNoAbs' : tr(u'fichier existant'),
161                   'Repertoire' : tr(u'repertoire')}
162       if mc.min == mc.max: commentaire=tr("Entrez ")+str(mc.min)
163       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
164
165       if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
166       else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
167       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
168
169       commentaire+=ctype
170       if self.max!=1 : commentaire+="s" 
171       return commentaire
172
173       
174
175
176    def setZoneInfo(self):
177       # info=str(self.nom)+'  '
178       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
179       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
180       pass
181       #self.editor.affiche_infos(info)