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