]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/feuille.py
Salome HOME
53e928e15211ec40e0c6664359d7c8e660c5fca0
[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.setIconesGenerales()
73        self.setCommentaire()
74        self.setZoneInfo()
75           
76
77    def setNom(self):
78        self.debutToolTip=""
79        nomTraduit=tr(self.objSimp.nom)
80        #if len(nomTraduit) >= nomMax :
81        #  nom=nomTraduit[0:nomMax]+'...'
82        #  self.label.setText(nomTraduit)
83        #  self.debutToolTip=nomTraduit+"\n"
84        longueur=QFontMetrics(self.label.font()).width(nomTraduit)
85        if longueur >= nomMax :
86          nouveauNom=self.formate(nomTraduit)
87          self.label.setText(nouveauNom)
88        else :   
89          self.label.setText(nomTraduit)
90
91    def agrandit(self):
92        # inutile pour certains widgets
93        if self.height() < 40 :
94           self.setMinimumHeight(50)
95           self.resize(self.width(),200)
96
97                                  
98    def setValeurs(self):
99       # print "passe dans setValeurs pour ", self.objSimp.nom
100       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
101         pass
102
103    def finCommentaire(self):
104        return ""
105
106    
107    def finCommentaireListe(self):
108         commentaire=""
109         mc = self.node.item.get_definition()
110         d_aides = { 'TXM' : 'chaines de caracteres',
111                   'R'   : 'reels',
112                   'I'   : 'entiers',
113                   'C'   : 'complexes'}
114         type = mc.type[0]
115         if not d_aides.has_key(type) :
116            if mc.min == mc.max:
117                commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
118            else :
119                commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
120         else :
121            if mc.min == mc.max:
122                commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
123            else :
124                commentaire=tr("Entrez entre ")+str(mc.min)+(" et  ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
125         aideval=self.node.item.aide()
126         commentaire=commentaire +  QString.toUtf8(QString(aideval))
127         self.monCommentaireLabel.setText(str(commentaire))
128         return str(commentaire)
129
130
131    def setSuggestion(self):
132       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
133          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
134          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
135
136    def setCommentaire(self):
137       c  = self.debutToolTip
138       #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
139       self.aide=c
140       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
141           c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
142           self.label.setToolTip(c2)
143           self.aide=str(self.objSimp.get_fr())+" "+c
144       else :
145          c+=self.finCommentaire()
146          if c != "" and c != None :
147             self.aide=c
148             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
149             c=str('<html><head/><body><p>')+c+"</p></body></html>"
150             self.label.setToolTip(c)
151
152
153
154    def showEvent(self, event):
155       if self.prendLeFocus==1 :
156          self.activateWindow()
157          "il faut deriver le showEvent pour" , self.nom
158          self.prendLeFocus=0
159       QWidget.showEvent(self,event)
160
161    def aideALaSaisie(self):
162       mc = self.node.item.get_definition()
163       mctype = mc.type[0]
164       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
165                   'R'   : tr("reel"),
166                   'I'   : tr("entier"),
167                   'C'   : tr("complexe"),
168                   'Matrice' : tr(u'Matrice'),
169                   'Fichier' : tr(u'fichier'),
170                   'FichierNoAbs' : tr(u'fichier existant'),
171                   'Repertoire' : tr(u'repertoire')}
172
173       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
174       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
175
176       if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
177       else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
178       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
179
180       commentaire+=ctype
181       if mc.max!=1 : commentaire+="s" 
182       return commentaire
183
184    def setZoneInfo(self):
185       # info=str(self.nom)+'  '
186       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
187       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
188       pass
189       #self.editor.affiche_infos(info)
190
191    def reaffiche(self):
192       #print "dans reaffiche de feuille", self.nom
193       if self.editor.jdc.aReafficher==True :
194          #print " j appelle le reaffiche de parentQt"
195          self.parentQt.reaffiche()
196
197          #PN PN PN pas satisfaisant
198          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
199          #print nodeAVoir.fenetre
200          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
201          #if nodeAVoir.fenetre.isVisible() : return
202          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
203          #nodeAVoir.fenetre.setFocus()
204          # return  # on est bien postionne
205
206          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
207             nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
208             try :
209                index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
210                if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
211                   try :
212                      nodeAVoir.fenetre.setValeursApresBouton()
213                   except :
214                      pass
215                else :
216                   self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
217             except :
218                pass
219       else :
220          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
221             try :
222                self.setValeursApresBouton()
223             except :
224                self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
225          else :
226             if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
227
228    def reaffichePourDeplier(self):
229       self.parentQt.reaffiche()
230
231    def rendVisible(self):
232        #print "jjjjjjjjjjjjjjjjjjjjj"
233        pass
234
235    def traiteClicSurLabel(self,texte):
236        #print self.aide 
237        aide=self.aide+"\n"+self.aideALaSaisie()
238        self.editor.affiche_commentaire(aide)
239
240    def formate(self,t):
241        if t.find('_')==0 :
242           newText=t[0:19]+'\n'+t[19:]
243        else:
244           listeNom=t.split('_')
245           newTexte=""
246           ligne=""
247           for n in listeNom:
248             if len(ligne)+len(n) < 25 : 
249                newTexte=newTexte+"_"+n
250                ligne+="_"+n
251             else :
252                newTexte=newTexte+"\n_"+n
253                ligne=""
254           #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
255           newText=newTexte[1:]
256        return newText
257       
258
259