]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/feuille.py
Salome HOME
e8dfbe6561ff7f04258cb6587c49537e7e270c8b
[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 determine import monEnvQT5
25 if monEnvQT5:
26    from PyQt5.QtWidgets import QToolButton ,QWidget
27    from PyQt5.QtGui import QFont, QFontMetrics
28    from PyQt5.QtCore import Qt
29 else :
30    from PyQt4.QtGui import *
31    from PyQt4.QtCore import *
32 from Extensions.i18n import tr
33
34
35 from gereIcones import ContientIcones
36 from gereIcones import FacultatifOuOptionnel
37 from qtSaisie    import SaisieValeur
38
39 nomMax=250
40 # ---------------------------------------------------------------------- #
41 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
42 # --------------------------------------------------------------------- #
43
44
45    def __init__(self,node,monSimpDef,nom,objSimp,parentQt,commande):
46        #print "Feuille", monSimpDef,nom,objSimp
47        QWidget.__init__(self,None)
48        self.node=node
49        self.node.fenetre=self
50
51        # on se positionne pour les icones
52        #os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__))))
53        self.setupUi(self)
54        self.prendLeFocus=0
55
56        maPolice= QFont("Times", 10)
57        self.setFont(maPolice)
58        self.setFocusPolicy(Qt.StrongFocus)
59
60        self.parentQt=parentQt
61        self.editor=self.node.editor
62        self.appliEficas=self.editor.appliEficas
63        self.repIcon=self.appliEficas.repIcon
64        self.monSimpDef=monSimpDef
65        self.nom=nom
66        self.objSimp=objSimp
67        self.node.fenetre=self
68        self.maCommande=commande
69
70        self.aRedimensionner=0
71        self.setSuggestion()
72        self.setValeurs()
73        self.setNom()
74        self.setValide()
75        self.setIconePoubelle()
76        self.setIconesFichier()
77        self.setIconesSalome()
78        self.setIconesGenerales()
79        self.setCommentaire()
80        self.setZoneInfo()
81           
82
83    def setNom(self):
84        self.debutToolTip=""
85        nomTraduit=tr(self.objSimp.nom)
86        longueur=QFontMetrics(self.label.font()).width(nomTraduit)
87        if longueur >= nomMax :
88          nouveauNom=self.formate(nomTraduit)
89          self.label.setText(nouveauNom)
90        else :   
91          self.label.setText(nomTraduit)
92
93    def agrandit(self):
94        # inutile pour certains widgets
95        if self.height() < 40 :
96           self.setMinimumHeight(50)
97           self.resize(self.width(),200)
98
99                                  
100    def setValeurs(self):
101       # print "passe dans setValeurs pour ", self.objSimp.nom
102       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
103         pass
104
105    def finCommentaire(self):
106        return ""
107
108    
109    def finCommentaireListe(self):
110         commentaire=""
111         mc = self.node.item.get_definition()
112         d_aides = { 'TXM' : 'chaines de caracteres',
113                   'R'   : 'reels',
114                   'I'   : 'entiers',
115                   'C'   : 'complexes'}
116         type = mc.type[0]
117         if not d_aides.has_key(type) :
118            if mc.min == mc.max:
119                commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
120            else :
121                if mc.max != "**" :
122                   commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
123                else :
124                   commentaire=""
125         else :
126            if mc.min == mc.max:
127                commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
128            else :
129                commentaire=tr("Entrez entre ")+str(mc.min)+(" et  ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
130         aideval=self.node.item.aide()
131         commentaire=commentaire +  tr(aideval)
132         self.monCommentaireLabel.setText(str(commentaire))
133         return str(commentaire)
134
135
136    def setSuggestion(self):
137       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
138          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
139          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
140
141    def setCommentaire(self):
142       c  = self.debutToolTip
143       #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
144       self.aide=c
145       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
146           c2 = '<html><head/><body><p>'+c+unicode(self.objSimp.get_fr())+"</p></body></html>"
147           self.label.setToolTip(c2)
148           self.aide=unicode(self.objSimp.get_fr())+" "+c
149       else :
150          c+=self.finCommentaire()
151          if c != "" and c != None :
152             self.aide=c
153             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
154             c=str('<html><head/><body><p>')+c+"</p></body></html>"
155             self.label.setToolTip(c)
156
157
158
159    def showEvent(self, event):
160       if self.prendLeFocus==1 :
161          self.activateWindow()
162          "il faut deriver le showEvent pour" , self.nom
163          self.prendLeFocus=0
164       QWidget.showEvent(self,event)
165
166    def aideALaSaisie(self):
167       mc = self.node.item.get_definition()
168       mctype = mc.type[0]
169       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
170                   'R'   : tr("reel"),
171                   'I'   : tr("entier"),
172                   'C'   : tr("complexe"),
173                   'Matrice' : tr(u'Matrice'),
174                   'Fichier' : tr(u'fichier'),
175                   'FichierNoAbs' : tr(u'fichier existant'),
176                   'Repertoire' : tr(u'repertoire')}
177
178       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
179       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
180
181       if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
182       else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
183       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
184
185       commentaire+=ctype
186       if mc.max!=1 : commentaire+="s" 
187       return commentaire
188
189    def setZoneInfo(self):
190       # info=str(self.nom)+'  '
191       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
192       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggeree : "self.monSimpDef.get_sug()
193       pass
194
195    def reaffiche(self):
196       #print "dans reaffiche de feuille", self.nom
197       if self.editor.jdc.aReafficher==True :
198          self.parentQt.reaffiche()
199
200          #PN PN PN pas satisfaisant
201          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
202          #print nodeAVoir.fenetre
203          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
204          #if nodeAVoir.fenetre.isVisible() : return
205          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
206          #nodeAVoir.fenetre.setFocus()
207          # return  # on est bien postionne
208
209          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
210             nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
211             try :
212                index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
213                if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
214                   try :
215                      nodeAVoir.fenetre.setValeursApresBouton()
216                   except :
217                      pass
218                else :
219                   self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
220             except :
221                pass
222       else :
223          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
224             try :
225                self.setValeursApresBouton()
226             except :
227                self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
228          else :
229             if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
230
231    def reaffichePourDeplier(self):
232       self.parentQt.reaffiche()
233
234    def rendVisible(self):
235        #print "jjjjjjjjjjjjjjjjjjjjj"
236        pass
237
238    #def enterEvent(self,event):
239    #   print "je passe dans enterEvent", self.nom
240    #   QWidget.enterEvent(self,event)
241
242    def traiteClicSurLabel(self,texte):
243        #print self.aide 
244        aide=self.aide+"\n"+self.aideALaSaisie()
245        self.editor.affiche_commentaire(aide)
246
247    def formate(self,t):
248        if t.find('_')==0 :
249           newText=t[0:19]+'\n'+t[19:]
250        else:
251           listeNom=t.split('_')
252           newTexte=""
253           ligne=""
254           for n in listeNom:
255             if len(ligne)+len(n) < 25 : 
256                newTexte=newTexte+"_"+n
257                ligne+="_"+n
258             else :
259                newTexte=newTexte+"\n_"+n
260                ligne=""
261           #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
262           newText=newTexte[1:]
263        return newText
264       
265
266