Salome HOME
Modifications liees a MT
[tools/eficas.git] / InterfaceQT4 / typeNode.py
index aab893dbced4d6b08e0bb641f1ed929b4bb415a2..f9e2e944269d4696ffe1bbfa95d0bd3ce77b95af 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Copyright (C) 2007-2013   EDF R&D
+# Copyright (C) 2007-2017   EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-from PyQt4 import *
-from PyQt4.QtGui import *
-from PyQt4.QtCore import *
-from Extensions.i18n import tr
-import types
+from __future__ import absolute_import
+try :
+   from builtins import object
+except : pass
 
+from PyQt5.QtWidgets import QAction, QMenu, QMessageBox
 
+from Extensions.i18n import tr
+import types
 
 #---------------------------#
-class PopUpMenuRacine :
+class PopUpMenuRacine(object) :
 #---------------------------#
 
-
     def createPopUpMenu(self):
         #print "createPopUpMenu"
         self.ParamApres = QAction(tr('Parametre'),self.tree)
-        self.tree.connect(self.ParamApres,SIGNAL("triggered()"),self.addParametersApres)
+        self.ParamApres.triggered.connect(self.addParametersApres)
         self.ParamApres.setStatusTip(tr("Insere un parametre"))
         self.menu = QMenu(self.tree)
         self.menu.addAction(self.ParamApres)
@@ -45,11 +46,11 @@ class PopUpMenuRacine :
         item.addParameters(True)
 
 #---------------------------#
-class PopUpMenuNodeMinimal :
+class PopUpMenuNodeMinimal(object) :
 #---------------------------#
 
     def createPopUpMenu(self):
-        #print "createPopUpMenu"
+        #print ("createPopUpMenu")
         #self.appliEficas.salome=True
         self.createActions()
         self.menu = QMenu(self.tree)
@@ -59,13 +60,24 @@ class PopUpMenuNodeMinimal :
         #items du menu
         self.menu.addAction(self.Supprime)
         if hasattr(self.appliEficas, 'mesScripts'):
-            if self.tree.currentItem().item.get_nom() in self.appliEficas.mesScripts.dict_commandes.keys() : 
-               self.ajoutScript()
+            if self.editor.code in  self.editor.appliEficas.mesScripts :
+               self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
+               if self.tree.currentItem().item.getNom() in self.dict_commandes_mesScripts : 
+                   self.ajoutScript()
     
     def ajoutScript(self):
     # cochon mais je n arrive pas a faire mieux avec le mecanisme de plugin
-        listeCommandes=self.appliEficas.mesScripts.dict_commandes[self.tree.currentItem().item.get_nom()]
-        if type(listeCommandes) != types.TupleType: listeCommandes=(listeCommandes,)
+    # a revoir avec un menu et un connect sur le triggered sur le menu ?
+        if hasattr(self.appliEficas, 'mesScripts'):
+            if self.editor.code in  self.editor.appliEficas.mesScripts :
+               self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
+            else : return
+
+        from Extensions import jdc_include
+        if isinstance(self.item.jdc,jdc_include.JDC_INCLUDE) : return
+
+        listeCommandes=self.dict_commandes_mesScripts[self.tree.currentItem().item.getNom()]
+        if type(listeCommandes) != tuple: listeCommandes=(listeCommandes,)
         numero=0
         for commande in listeCommandes :
            conditionSalome=commande[3]
@@ -74,82 +86,87 @@ class PopUpMenuNodeMinimal :
            tip=commande[5]
            self.action=QAction(label,self.tree)
            self.action.setStatusTip(tip)
-           if numero==4: 
-              self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction4)
-           if numero==3: 
-              self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction3)
-              numero=4
-           if numero==2: 
-              self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction2)
-              numero=3
-           if numero==1: 
-              self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction1)
-              numero=2
-           if numero==0: 
-              self.tree.connect(self.action,SIGNAL("triggered()"),self.AppelleFonction0)
-              numero=1
+           if numero==4: self.action.triggered.connect(self.appelleFonction4)
+           if numero==3: self.action.triggered.connect(self.appelleFonction3); numero=4
+           if numero==2: self.action.triggered.connect(self.appelleFonction2); numero=3
+           if numero==1: self.action.triggered.connect(self.appelleFonction1); numero=2
+           if numero==0: self.action.triggered.connect(self.appelleFonction0); numero=1
            self.menu.addAction(self.action)
 
 
-    def AppelleFonction0(self):
-        self.AppelleFonction(0)
+    def appelleFonction0(self):
+        self.appelleFonction(0)
 
-    def AppelleFonction1(self):
-        self.AppelleFonction(1)
+    def appelleFonction1(self):
+        self.appelleFonction(1)
 
-    def AppelleFonction2(self):
-        self.AppelleFonction(2)
+    def appelleFonction2(self):
+        self.appelleFonction(2)
 
-    def AppelleFonction3(self):
-        self.AppelleFonction(3)
+    def appelleFonction3(self):
+        self.appelleFonction(3)
 
-    def AppelleFonction4(self):
-        self.AppelleFonction(4)
+    def appelleFonction4(self):
+        self.appelleFonction(4)
 
-
-    def AppelleFonction(self,numero):
-        listeCommandes=self.appliEficas.mesScripts.dict_commandes[self.tree.currentItem().item.get_nom()]
+    def appelleFonction(self,numero,nodeTraite=None):
+        if nodeTraite==None : nodeTraite=self.tree.currentItem()
+        nomCmd=nodeTraite.item.getNom()
+        if hasattr(self.appliEficas, 'mesScripts'):
+            if self.editor.code in  self.editor.appliEficas.mesScripts :
+               self.dict_commandes_mesScripts=self.appliEficas.mesScripts[self.editor.code].dict_commandes
+            else : return
+        listeCommandes=self.dict_commandes_mesScripts[nomCmd]
         commande=listeCommandes[numero]
         conditionValid=commande[4]
-        if (self.tree.currentItem().item.isvalid() == 0 and conditionValid == True):
+
+
+        if (nodeTraite.item.isValid() == 0 and conditionValid == True):
                  QMessageBox.warning( None, 
                              tr("item invalide"),
-                             tr("l item doit etre valide"),
-                             tr("&Ok"))
-                return
+                             tr("l item doit etre valide"),)
+                 return
         fonction=commande[0]
         listenomparam=commande[2]
         listeparam=[]
         for p in listenomparam:
-            if hasattr(self.tree.currentItem(),p):
-               listeparam.append(getattr(self.tree.currentItem(),p))
+            if hasattr(nodeTraite,p):
+               listeparam.append(getattr(nodeTraite,p))
             if p=="self" : listeparam.append(self)
+           
         try :
-           fonction(listeparam,self.appliEficas)
+           res, commentaire= fonction(listeparam)
+           if not res :
+                 QMessageBox.warning( None, 
+                             tr("echec de la fonction"),
+                             tr(commentaire),)
+                 return
         except :
-           fonction(listeparam)
+           pass
+        
+
 
 
     def createActions(self):
         self.CommApres = QAction(tr('apres'),self.tree)
-        self.tree.connect(self.CommApres,SIGNAL("triggered()"),self.addCommApres)
+        self.CommApres.triggered.connect(self.addCommApres)
         self.CommApres.setStatusTip(tr("Insere un commentaire apres la commande "))
         self.CommAvant = QAction(tr('avant'),self.tree)
-        self.tree.connect(self.CommAvant,SIGNAL("triggered()"),self.addCommAvant)
+        self.CommAvant.triggered.connect(self.addCommAvant)
         self.CommAvant.setStatusTip(tr("Insere un commentaire avant la commande "))
 
         self.ParamApres = QAction(tr('apres'),self.tree)
-        self.tree.connect(self.ParamApres,SIGNAL("triggered()"),self.addParametersApres)
+        self.ParamApres.triggered.connect(self.addParametersApres)
         self.ParamApres.setStatusTip(tr("Insere un parametre apres la commande "))
         self.ParamAvant = QAction(tr('avant'),self.tree)
-        self.tree.connect(self.ParamAvant,SIGNAL("triggered()"),self.addParametersAvant)
+        self.ParamAvant.triggered.connect(self.addParametersAvant)
         self.ParamAvant.setStatusTip(tr("Insere un parametre avant la commande "))
 
         self.Supprime = QAction(tr('Supprimer'),self.tree)
-        self.tree.connect(self.Supprime,SIGNAL("triggered()"),self.supprimeNoeud)
+        self.Supprime.triggered.connect(self.supprimeNoeud)
         self.Supprime.setStatusTip(tr("supprime le mot clef "))
         self.Documentation = QAction(tr('Documentation'),self.tree)
-        self.tree.connect(self.Documentation,SIGNAL("triggered()"),self.viewDoc)
+        self.Documentation.triggered.connect(self.viewDoc)
         self.Documentation.setStatusTip(tr("documentation sur la commande "))
 
     def supprimeNoeud(self):
@@ -158,12 +175,12 @@ class PopUpMenuNodeMinimal :
 
     def viewDoc(self):
         self.node=self.tree.currentItem()
-        cle_doc = self.node.item.get_docu()
+        cle_doc = self.node.item.getDocu()
         if cle_doc == None :
             QMessageBox.information( self.editor,tr( "Documentation Vide"), \
                                     tr("Aucune documentation n'est associee a ce noeud"))
             return
-        commande = self.editor.appliEficas.CONFIGURATION.exec_acrobat
+        commande = self.editor.appliEficas.maConfiguration.exec_acrobat
         try :
             f=open(commande,"rb")
         except :
@@ -174,7 +191,7 @@ class PopUpMenuNodeMinimal :
         if cle_doc.startswith('http:'):
            fichier = cle_doc
         else :
-            fichier = os.path.abspath(os.path.join(self.editor.CONFIGURATION.path_doc,
+            fichier = os.path.abspath(os.path.join(self.editor.maConfiguration.path_doc,
                                        cle_doc))
             try :
                f=open(fichier,"rb")
@@ -206,6 +223,10 @@ class PopUpMenuNodeMinimal :
         item= self.tree.currentItem()
         item.addComment(False)
 
+    def deplieCeNiveau(self):
+        item= self.tree.currentItem()
+        item.deplieCeNiveau()
+
 #--------------------------------------------#
 class PopUpMenuNodePartiel (PopUpMenuNodeMinimal):
 #---------------------------------------------#
@@ -230,12 +251,12 @@ class PopUpMenuNode(PopUpMenuNodePartiel) :
     def createPopUpMenu(self):
         PopUpMenuNodePartiel.createPopUpMenu(self)
         self.Commente = QAction(tr('ce noeud'),self.tree)
-        self.tree.connect(self.Commente,SIGNAL("triggered()"),self.Commenter)
+        self.Commente.triggered.connect(self.commenter)
         self.Commente.setStatusTip(tr("commente le noeud "))
         self.commentMenu.addAction(self.Commente)
         self.menu.removeAction(self.Supprime)
         self.menu.addAction(self.Supprime)
 
-    def Commenter(self):
+    def commenter(self):
         item= self.tree.currentItem()
         item.commentIt()