Salome HOME
optim eciture
[tools/eficas.git] / InterfaceQT4 / feuille.py
index 126b2f9afd412b48a32cc25dd99e51e3332b3318..717faa8e2e7a15d70229f810245d8f3f6c007705 100644 (file)
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 # Modules Python
-import string,types,os
+from __future__ import absolute_import
+try :
+  from builtins import str
+except :
+  pass
+import types,os
 import traceback
 
-from PyQt4 import *
-from PyQt4.QtGui import *
-from PyQt4.QtCore import *
+from PyQt5.QtWidgets import QToolButton ,QWidget
+from PyQt5.QtGui import QFont, QFontMetrics
+from PyQt5.QtCore import Qt
+
 from Extensions.i18n import tr
 
-from gereIcones import ContientIcones
-from gereIcones import FacultatifOuOptionnel
-from qtSaisie    import SaisieValeur
+from .gereIcones import ContientIcones
+from .gereIcones import FacultatifOuOptionnel
+from .qtSaisie    import SaisieValeur
 
-nomMax=26
+nomMax=250
 # ---------------------------------------------------------------------- #
 class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
 # --------------------------------------------------------------------- #
@@ -41,11 +47,15 @@ class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
        QWidget.__init__(self,None)
        self.node=node
        self.node.fenetre=self
+
+       # on se positionne pour les icones
+       #os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__))))
        self.setupUi(self)
        self.prendLeFocus=0
 
        maPolice= QFont("Times", 10)
        self.setFont(maPolice)
+       self.setFocusPolicy(Qt.StrongFocus)
 
        self.parentQt=parentQt
        self.editor=self.node.editor
@@ -62,22 +72,37 @@ class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
        self.setValeurs()
        self.setNom()
        self.setValide()
-       self.setPoubelle()
-       self.setIcones()
+       self.setIconePoubelle()
+       self.setIconesFichier()
+       self.setIconesSalome()
+       self.setIconesGenerales()
        self.setCommentaire()
        self.setZoneInfo()
-          
+     
 
    def setNom(self):
        self.debutToolTip=""
        nomTraduit=tr(self.objSimp.nom)
-       if len(nomTraduit) >= nomMax :
-         nom=nomTraduit[0:nomMax]+'...'
-         self.label.setText(nomTraduit)
-         self.debutToolTip=nomTraduit+"\n"
+       longueur=QFontMetrics(self.label.font()).width(nomTraduit)
+       if longueur >= nomMax :
+         nouveauNom=self.formate(nomTraduit)
+         self.label.setText(nouveauNom)
        else :   
          self.label.setText(nomTraduit)
 
+   def agrandit(self):
+       # inutile pour certains widgets
+       if self.height() < 40 :
+          self.setMinimumHeight(50)
+          self.resize(self.width(),200)
+
+   #def mousePressEvent(self, event):
+     #print 'mousePressEvent'
+     #import inspect
+     #print (inspect.getmro(self.__class__))
+     #self.__class__.mousePressEvent(self, event)
+
+
                                  
    def setValeurs(self):
       # print "passe dans setValeurs pour ", self.objSimp.nom
@@ -87,6 +112,34 @@ class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
    def finCommentaire(self):
        return ""
 
+   
+   def finCommentaireListe(self):
+        commentaire=""
+        mc = self.node.item.get_definition()
+        d_aides = { 'TXM' : 'chaines de caracteres',
+                  'R'   : 'reels',
+                  'I'   : 'entiers',
+                  'C'   : 'complexes'}
+        type = mc.type[0]
+        if not type in d_aides :
+           if mc.min == mc.max:
+               commentaire=tr("Entrez ")+str(mc.min)+tr(" valeurs ")+'\n'
+           else :
+               if mc.max != "**" :
+                  commentaire=tr("entre ")+str(mc.min)+tr(" et ")+str(mc.max)+tr(" valeurs ")+'\n'
+               else :
+                  commentaire=""
+        else :
+           if mc.min == mc.max:
+               commentaire=tr("Entrez ")+str(mc.min)+" "+tr(d_aides[type])+'\n'
+           else :
+               commentaire=tr("Entrez entre ")+"\n"+str(mc.min)+(" et  ")+str(mc.max) +" " +tr(d_aides[type])+'\n'
+        aideval=self.node.item.aide()
+        commentaire=commentaire +  tr(aideval)
+        self.monCommentaireLabel.setText(str(commentaire))
+        return str(commentaire)
+
+
    def setSuggestion(self):
       if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "":
          suggere=str('<html><head/><body><p><span style=" font-size:8pt;">suggestion : ')+str(self.monSimpDef.get_sug())+"</span></p></body></html>"
@@ -94,45 +147,23 @@ class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
 
    def setCommentaire(self):
       c  = self.debutToolTip
-      if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
+      #if self.node.item.definition.validators : c+=self.node.item.definition.validators.aide()
+      self.aide=c
       if self.objSimp.get_fr() != None and self.objSimp.get_fr() != "":
-          c2 = '<html><head/><body><p>'+c+str(self.objSimp.get_fr())+"</p></body></html>"
+          #c2 = '<html><head/><body><p>'+c+self.objSimp.get_fr().decode('latin-1','replace')+"</p></body></html>"
+          c2 = '<html><head/><body><p>'+c+self.objSimp.get_fr()
+          #c2 = '<html><head/><body><p>'+c+self.objSimp.get_fr()+"</p></body></html>"
           self.label.setToolTip(c2)
+          #self.aide=self.objSimp.get_fr().decode('latin-1','ignore')+" "+c
+          self.aide=self.objSimp.get_fr()+" "+c
       else :
          c+=self.finCommentaire()
          if c != "" and c != None :
+            self.aide=c
             #c=str('<html><head/><body><p><span style=" font-size:8pt; ">')+c+"</span></p></body></html>"
             c=str('<html><head/><body><p>')+c+"</p></body></html>"
             self.label.setToolTip(c)
 
-   def setIcones(self):
-
-       mctype = self.monSimpDef.type[0]
-       # selon 
-       if ( hasattr(self,"BFichier")): 
-          if mctype == "Repertoire":
-             self.BRepertoire=self.BFichier
-             self.connect(self.BRepertoire,SIGNAL("clicked()"),self.BRepertoirePressed)
-          else :
-            #icon = QIcon(self.repIcon+"/visuFichier.png")
-             self.connect(self.BFichier,SIGNAL("clicked()"),self.BFichierPressed)
-             self.connect(self.BVisuFichier,SIGNAL("clicked()"),self.BFichierVisu)
-          return
-
-       if ( hasattr(self,"BSalome")): 
-          enable_salome_selection = self.editor.salome and \
-              (('grma' in repr(mctype)) or ('grno' in repr(mctype)) or ('SalomeEntry' in repr(mctype)) or
-               (hasattr(mctype, "enable_salome_selection") and mctype.enable_salome_selection))
-          if  enable_salome_selection:
-              self.connect(self.BSalome,SIGNAL("pressed()"),self.BSalomePressed)
-
-              if not(('grma' in repr(mctype)) or ('grno' in repr(mctype))) or not(self.editor.salome):
-                self.BView2D.close()
-              else :
-                self.connect(self.BView2D,SIGNAL("clicked()"),self.BView2DPressed)
-          else:
-              self.BSalome.close()
-              self.BView2D.close()
 
 
    def showEvent(self, event):
@@ -143,10 +174,9 @@ class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
       QWidget.showEvent(self,event)
 
    def aideALaSaisie(self):
-      return
       mc = self.node.item.get_definition()
       mctype = mc.type[0]
-      d_aide = { 'TXM' : tr(u"chaine de caracteres"),
+      d_aides = { 'TXM' : tr(u"chaine de caracteres"),
                   'R'   : tr("reel"),
                   'I'   : tr("entier"),
                   'C'   : tr("complexe"),
@@ -154,20 +184,95 @@ class Feuille(QWidget,ContientIcones,SaisieValeur,FacultatifOuOptionnel):
                   'Fichier' : tr(u'fichier'),
                   'FichierNoAbs' : tr(u'fichier existant'),
                   'Repertoire' : tr(u'repertoire')}
-      if mc.min == mc.max: commentaire=tr("Entrez ")+str(mc.min)
+
+      if mc.min == mc.max: commentaire=tr("Entrez ")+" "+str(mc.min)+" "
       else :               commentaire=tr("Entrez entre ")+str(mc.min)+tr(" et ")+str(mc.max)
 
-      if type(mctype) == types.ClassType: ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
-      else:                               ctype = d_aides.get(mctype, tr("Type de base inconnu"))
+      try :
+         if issubclass(mctype,object) : ctype = getattr(mctype, 'help_message', tr("Type de base inconnu"))
+         else : ctype = d_aides.get(mctype, tr("Type de base inconnu"))
+      except:                        
+         ctype = d_aides.get(mctype, tr("Type de base inconnu"))
       if ctype == tr("Type de base inconnu") and "Tuple" in str(mctype): ctype=str(mctype)
 
       commentaire+=ctype
-      if self.max!=1 : commentaire+="s" 
+      if mc.max!=1 : commentaire+="s" 
       return commentaire
 
    def setZoneInfo(self):
       # info=str(self.nom)+'  '
       # if self.monSimpDef.get_fr() != None and self.monSimpDef.get_fr() != "": info+=self.monSimpDef.get_sug() +" "
-      # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggérée : "self.monSimpDef.get_sug()
+      # if self.monSimpDef.get_sug() != None and self.monSimpDef.get_sug() != "": info+="Valeur suggeree : "self.monSimpDef.get_sug()
       pass
-      #self.editor.affiche_infos(info)
+
+   def reaffiche(self):
+
+      if self.editor.jdc.aReafficher==True :
+         self.parentQt.reaffiche()
+
+         #PN PN PN pas satisfaisant
+         #nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
+         #print nodeAVoir.fenetre
+         #print "nodeAVoir.fenetre.isVisible()", nodeAVoir.fenetre.isVisible()
+         #if nodeAVoir.fenetre.isVisible() : return
+         #self.editor.fenetreCentraleAffichee.rendVisibleNoeud(nodeAVoir)
+         #nodeAVoir.fenetre.setFocus()
+         # return  # on est bien postionne
+
+         if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
+            nodeAVoir=self.parentQt.node.chercheNoeudCorrespondant(self.objSimp)
+            try :
+               index=self.editor.fenetreCentraleAffichee.listeAffichageWidget.index(nodeAVoir.fenetre.AAfficher)
+               if (index==len(self.editor.fenetreCentraleAffichee.listeAffichageWidget)-1) :
+                  try :
+                     nodeAVoir.fenetre.setValeursApresBouton()
+                  except :
+                     pass
+               else :
+                  self.editor.fenetreCentraleAffichee.afficheSuivant(nodeAVoir.fenetre.AAfficher)
+            except :
+               pass
+      else :
+         if self.objSimp.isvalid() and hasattr(self, 'AAfficher'):
+            try :
+               self.setValeursApresBouton()
+            except :
+               pass
+            self.editor.fenetreCentraleAffichee.afficheSuivant(self.AAfficher)
+         else :
+            if hasattr(self, 'AAfficher'): self.AAfficher.setFocus(7)
+
+   def reaffichePourDeplier(self):
+      self.parentQt.reaffiche()
+
+   def rendVisible(self):
+       pass
+
+   #def enterEvent(self,event):
+   #   print "je passe dans enterEvent", self.nom
+   #   QWidget.enterEvent(self,event)
+
+   def traiteClicSurLabel(self,texte):
+       aide=self.aide.encode('latin-1', 'ignore').decode('latin-1')+"\n"+self.aideALaSaisie().encode('latin-1', 'ignore').decode('latin-1')
+       self.editor.affiche_commentaire(aide)
+
+   def formate(self,t):
+       if t.find('_')==0 :
+          newText=t[0:19]+'\n'+t[19:]
+       else:
+          listeNom=t.split('_')
+          newTexte=""
+          ligne=""
+          for n in listeNom:
+            if len(ligne)+len(n) < 25 : 
+               newTexte=newTexte+"_"+n
+               ligne+="_"+n
+            else :
+               newTexte=newTexte+"\n_"+n
+               ligne=""
+          #newTexte=t[0:t.rfind('_')]+'\n'+ t[t.rfind('_'):]
+          newText=newTexte[1:]
+       return newText
+      
+