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