]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/feuille.py
Salome HOME
2994815793dbdf05db1e865264c2929b0dfea095
[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 from __future__ import absolute_import
22 try :
23   from builtins import str
24 except :
25   pass
26 import types,os
27 import traceback
28
29 from PyQt5.QtWidgets import QToolButton ,QWidget
30 from PyQt5.QtGui import QFont, QFontMetrics
31 from PyQt5.QtCore import Qt
32
33 from Extensions.i18n import tr
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    #def mousePressEvent(self, event):
100      #print 'mousePressEvent'
101      #import inspect
102      #print (inspect.getmro(self.__class__))
103      #self.__class__.mousePressEvent(self, event)
104
105
106                                  
107    def setValeurs(self):
108       # print "passe dans setValeurs pour ", self.objSimp.nom
109       # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
110         pass
111
112    def finCommentaire(self):
113        return ""
114
115    
116    def finCommentaireListe(self):
117         commentaire=""
118         mc = self.node.item.get_definition()
119         d_aides = { 'TXM' : 'chaines de caracteres',
120                   'R'   : 'reels',
121                   'I'   : 'entiers',
122                   'C'   : 'complexes'}
123         type = mc.type[0]
124         if not type in d_aides :
125            if mc.min == mc.max:
126                commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
127            else :
128                if mc.max != "**" :
129                   commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
130                else :
131                   commentaire=""
132         else :
133            if mc.min == mc.max:
134                commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
135            else :
136                commentaire=tr("Entrez entre ")+"\n"+str(mc.min)+(" et  ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
137         aideval=self.node.item.aide()
138         commentaire=commentaire +  tr(aideval)
139         self.monCommentaireLabel.setText(str(commentaire))
140         return str(commentaire)
141
142
143    def setSuggestion(self):
144       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
145          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
146          if hasattr(self,'lineEditVal'): self.lineEditVal.setToolTip(suggere)
147
148    def setCommentaire(self):
149       c  = self.debutToolTip
150       #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
151       self.aide=c
152       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
153           c2 = '<html><head/><body><p>'+c+self.objSimp.get_fr().decode('latin-1','replace')+"</p></body></html>"
154           #c2 = '<html><head/><body><p>'+c+self.objSimp.get_fr()+"</p></body></html>"
155           self.label.setToolTip(c2)
156           self.aide=self.objSimp.get_fr().decode('latin-1','ignore')+" "+c
157           #self.aide=self.objSimp.get_fr()+" "+c
158       else :
159          c+=self.finCommentaire()
160          if c != "" and c != None :
161             self.aide=c
162             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
163             c=str('<html><head/><body><p>')+c+"</p></body></html>"
164             self.label.setToolTip(c)
165
166
167
168    def showEvent(self, event):
169       if self.prendLeFocus==1 :
170          self.activateWindow()
171          "il faut deriver le showEvent pour" , self.nom
172          self.prendLeFocus=0
173       QWidget.showEvent(self,event)
174
175    def aideALaSaisie(self):
176       mc = self.node.item.get_definition()
177       mctype = mc.type[0]
178       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
179                   'R'   : tr("reel"),
180                   'I'   : tr("entier"),
181                   'C'   : tr("complexe"),
182                   'Matrice' : tr(u'Matrice'),
183                   'Fichier' : tr(u'fichier'),
184                   'FichierNoAbs' : tr(u'fichier existant'),
185                   'Repertoire' : tr(u'repertoire')}
186
187       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
188       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
189
190       try :
191          if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
192          else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
193       except:                        
194          ctype = d_aides.get(mctype, tr("Type de base inconnu"))
195       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
196
197       commentaire+=ctype
198       if mc.max!=1 : commentaire+="s" 
199       return commentaire
200
201    def setZoneInfo(self):
202       # info=str(self.nom)+'  '
203       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
204       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggeree : "self.monSimpDef.get_sug()
205       pass
206
207    def reaffiche(self):
208
209       if self.editor.jdc.aReafficher==True :
210          self.parentQt.reaffiche()
211
212          #PN PN PN pas satisfaisant
213          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
214          #print nodeAVoir.fenetre
215          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
216          #if nodeAVoir.fenetre.isVisible() : return
217          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
218          #nodeAVoir.fenetre.setFocus()
219          # return  # on est bien postionne
220
221          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
222             nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
223             try :
224                index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
225                if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
226                   try :
227                      nodeAVoir.fenetre.setValeursApresBouton()
228                   except :
229                      pass
230                else :
231                   self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
232             except :
233                pass
234       else :
235          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
236             try :
237                self.setValeursApresBouton()
238             except :
239                pass
240             self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
241          else :
242             if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
243
244    def reaffichePourDeplier(self):
245       self.parentQt.reaffiche()
246
247    def rendVisible(self):
248        pass
249
250    #def enterEvent(self,event):
251    #   print "je passe dans enterEvent", self.nom
252    #   QWidget.enterEvent(self,event)
253
254    def traiteClicSurLabel(self,texte):
255        aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
256        self.editor.affiche_commentaire(aide)
257
258    def formate(self,t):
259        if t.find('_')==0 :
260           newText=t[0:19]+'\n'+t[19:]
261        else:
262           listeNom=t.split('_')
263           newTexte=""
264           ligne=""
265           for n in listeNom:
266             if len(ligne)+len(n) < 25 : 
267                newTexte=newTexte+"_"+n
268                ligne+="_"+n
269             else :
270                newTexte=newTexte+"\n_"+n
271                ligne=""
272           #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
273           newText=newTexte[1:]
274        return newText
275       
276
277