]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/feuille.py
Salome HOME
pb de check box
[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 ")+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           self.label.setToolTip(c2)
155           self.aide=self.objSimp.get_fr().decode('latin-1','ignore')+" "+c
156       else :
157          c+=self.finCommentaire()
158          if c != "" and c != None :
159             self.aide=c
160             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
161             c=str('<html><head/><body><p>')+c+"</p></body></html>"
162             self.label.setToolTip(c)
163
164
165
166    def showEvent(self, event):
167       if self.prendLeFocus==1 :
168          self.activateWindow()
169          "il faut deriver le showEvent pour" , self.nom
170          self.prendLeFocus=0
171       QWidget.showEvent(self,event)
172
173    def aideALaSaisie(self):
174       mc = self.node.item.get_definition()
175       mctype = mc.type[0]
176       d_aides = { 'TXM' : tr(u"chaine de caracteres"),
177                   'R'   : tr("reel"),
178                   'I'   : tr("entier"),
179                   'C'   : tr("complexe"),
180                   'Matrice' : tr(u'Matrice'),
181                   'Fichier' : tr(u'fichier'),
182                   'FichierNoAbs' : tr(u'fichier existant'),
183                   'Repertoire' : tr(u'repertoire')}
184
185       if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
186       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
187
188       try :
189          if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
190          else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
191       except:                        
192          ctype = d_aides.get(mctype, tr("Type de base inconnu"))
193       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
194
195       commentaire+=ctype
196       if mc.max!=1 : commentaire+="s" 
197       return commentaire
198
199    def setZoneInfo(self):
200       # info=str(self.nom)+'  '
201       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
202       # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggeree : "self.monSimpDef.get_sug()
203       pass
204
205    def reaffiche(self):
206
207       if self.editor.jdc.aReafficher==True :
208          self.parentQt.reaffiche()
209
210          #PN PN PN pas satisfaisant
211          #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
212          #print nodeAVoir.fenetre
213          #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
214          #if nodeAVoir.fenetre.isVisible() : return
215          #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
216          #nodeAVoir.fenetre.setFocus()
217          # return  # on est bien postionne
218
219          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
220             nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
221             try :
222                index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
223                if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
224                   try :
225                      nodeAVoir.fenetre.setValeursApresBouton()
226                   except :
227                      pass
228                else :
229                   self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
230             except :
231                pass
232       else :
233          if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
234             try :
235                self.setValeursApresBouton()
236             except :
237                pass
238             self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
239          else :
240             if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
241
242    def reaffichePourDeplier(self):
243       self.parentQt.reaffiche()
244
245    def rendVisible(self):
246        pass
247
248    #def enterEvent(self,event):
249    #   print "je passe dans enterEvent", self.nom
250    #   QWidget.enterEvent(self,event)
251
252    def traiteClicSurLabel(self,texte):
253        aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
254        self.editor.affiche_commentaire(aide)
255
256    def formate(self,t):
257        if t.find('_')==0 :
258           newText=t[0:19]+'\n'+t[19:]
259        else:
260           listeNom=t.split('_')
261           newTexte=""
262           ligne=""
263           for n in listeNom:
264             if len(ligne)+len(n) < 25 : 
265                newTexte=newTexte+"_"+n
266                ligne+="_"+n
267             else :
268                newTexte=newTexte+"\n_"+n
269                ligne=""
270           #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
271           newText=newTexte[1:]
272        return newText
273       
274
275