Salome HOME
souci d icone
[tools/eficas.git] / InterfaceQT4 / readercata.py
index 9137cd3e31990d0043ff055ff26c6d5dbf71f790..b3def9c2fc85f2ccc3c01d8698de248f0778a272 100644 (file)
     Il s'appuie sur la classe READERCATA
 """
 # Modules Python
+from __future__ import absolute_import
+from __future__ import print_function
+try :
+   from builtins import str
+   from builtins import object
+except : pass
+
 import time
 import os,sys,py_compile
 import traceback
-import cPickle
+import six.moves.cPickle
 import re
 import types
 
@@ -38,19 +45,15 @@ import analyse_catalogue
 import analyse_catalogue_initial
 import autre_analyse_cata
 import uiinfo
-from monChoixCata import MonChoixCata
+from .monChoixCata import MonChoixCata
 from Extensions.i18n import tr
 from Extensions.eficas_exception import EficasException
 
-from determine import monEnvQT5
-if monEnvQT5 :
-   from PyQt5.QtWidgets import QMessageBox, QApplication, QDialog
-else :
-   from PyQt4.QtGui  import *
+from PyQt5.QtWidgets import QMessageBox, QApplication, QDialog
 
 
 
-class READERCATA:
+class READERCATA(object):
 
    def __init__(self,QWParent, appliEficas):
       self.QWParent=QWParent
@@ -65,7 +68,14 @@ class READERCATA:
       self.fic_cata=None
       self.OpenCata()
       self.cataitem=None
-      if self.code=="TELEMAC": self.cree_dico_inverse()
+      self.cree_dico_inverse()
+      if self.code=="TELEMAC": self.cree_dico_CasToCata()
+      #for k in self.dicoInverse:
+      #   genea= self.dicoInverse[k]
+      #   for t in genea :
+      #       print t[0]
+      #   print "\n"
+
 
    def OpenCata(self):
       """ 
@@ -80,10 +90,10 @@ class READERCATA:
       for catalogue in self.appliEficas.CONFIGURATION.catalogues:
           if isinstance(catalogue, CatalogDescription):
               all_cata_list.append(catalogue)
-          elif isinstance(catalogue, types.TupleType):
+          elif isinstance(catalogue, tuple):
               all_cata_list.append(CatalogDescription.create_from_tuple(catalogue))
           else:
-              print "Catalog description cannot be interpreted: ", catalogue
+              print(("Catalog description cannot be interpreted: ", catalogue))
 
       # This filter is only useful for codes that have subcodes (like MAP).
       # Otherwise, the "code" attribute of the catalog description can (should) be None.
@@ -136,7 +146,7 @@ class READERCATA:
 
       if self.fic_cata == None :
           if self.appliEficas.salome == 0 :
-             print "Pas de catalogue pour code %s, version %s" %(self.code,self.version_code)
+             print(("Pas de catalogue pour code %s, version %s" %(self.code,self.version_code)))
              sys.exit(1)
           else :
              self.appliEficas.close()
@@ -148,7 +158,7 @@ class READERCATA:
       self.cata = self.import_cata(self.fic_cata)
       if not self.cata :          
           QMessageBox.critical( self.QWParent, tr("Import du catalogue"),tr("Impossible d'importer le catalogue ")+ self.fic_cata)
-         self.appliEficas.close()
+          self.appliEficas.close()
           if self.appliEficas.salome == 0 :
              sys.exit(1)
       #
@@ -197,7 +207,7 @@ class READERCATA:
              a=self.appliEficas.CONFIGURATION.dRepMat[self.version_code]
           except :
              if self.code == "ASTER" :
-                print "Probleme avec le repertoire materiau"
+                print ("Probleme avec le repertoire materiau")
              a='.'
       self.appliEficas.CONFIGURATION.rep_mat=a
 
@@ -211,9 +221,9 @@ class READERCATA:
       self.appliEficas.listeAEnlever.append(rep_cata)
 
       
-      if sys.modules.has_key(nom_cata):
+      if nom_cata in list(sys.modules.keys()) :
         del sys.modules[nom_cata]
-      for k in sys.modules.keys():
+      for k in sys.modules:
         if k[0:len(nom_cata)+1] == nom_cata+'.':
           del sys.modules[k]
 
@@ -235,7 +245,7 @@ class READERCATA:
       try :
           o=__import__(nom_cata)
           return o
-      except Exception,e:
+      except Exception as e:
           traceback.print_exc()
           return 0
 
@@ -249,7 +259,6 @@ class READERCATA:
           contient le nom des mots cles dans le bon ordre
       """ 
       self.cata_ordonne_dico,self.appliEficas.liste_simp_reel=autre_analyse_cata.analyse_catalogue(self.cata)
-      #print self.cata_ordonne_dico,self.appliEficas.liste_simp_reel
 
    def Retrouve_Ordre_Cata_Standard(self):
       """ 
@@ -299,7 +308,7 @@ class READERCATA:
         self.fic_doc=getattr(self.appliEficas.CONFIGURATION,fic_doc )
         f=open(self.fic_doc)
       except:
-        print "Pas de fichier associe contenant des clefs documentaires"
+        print ("Pas de fichier associe contenant des clefs documentaires")
         return
 
       dict_clef_docu={}
@@ -309,7 +318,7 @@ class READERCATA:
           docu=l[deb:-1]
           dict_clef_docu[clef]=docu
       for oper in self.cata.JdC.commandes:
-           if dict_clef_docu.has_key(oper.nom):
+           if oper.nom in dict_clef_docu :
               oper.docu=dict_clef_docu[oper.nom]
 
    def cree_dico_inverse(self):
@@ -317,38 +326,33 @@ class READERCATA:
         self.dicoMC={} 
         listeEtapes=self.cata[0].JdC.commandes
         for e in self.cata[0].JdC.commandes:
-        #for e in (self.cata[0].JdC.commandes[0],):
-            #print e.nom
             self.traite_entite(e)
-        #for e in self.cata[0].JdC.commandes:
-        #    self.cree_rubrique(e,self.dico,0)
-        #print self.dicoInverse
-
-        #from Extensions import localisation
-        #app=QApplication
-        # tres dommage  A Revoir
-        #localisation.localise(app,"fr")
-        self.dicoInverseFrancais={}
-        self.dicoFrancaisAnglais={}
-        self.dicoAnglaisFrancais={}
-        for k in self.dicoInverse.keys():
-            listefr=[]
-            for nom, obj in self.dicoInverse[k] :
-                listefr.append((tr(nom),obj))
-                self.dicoFrancaisAnglais[tr(nom)]=nom
-                self.dicoAnglaisFrancais[nom]=tr(nom)
-            self.dicoInverseFrancais[tr(k)]=listefr
-            #print tr(k),listefr
-        if self.appliEficas.langue=="ang" : localisation.localise(app,"en")
+
+        #self.dicoFrancaisAnglais={}
+        #self.dicoAnglaisFrancais={}
+        #for k in self.dicoInverse:
+        #    listefr=[]
+        #    for nom, obj in self.dicoInverse[k] :
+        #        listefr.append((tr(nom),obj))
+        #        self.dicoFrancaisAnglais[tr(nom)]=nom
+        #        self.dicoAnglaisFrancais[nom]=tr(nom)
+        #    self.dicoInverseFrancais[tr(k)]=listefr
+        #    #print tr(k),listefr
+
+   
+   def cree_dico_CasToCata(self):
+        if self.appliEficas.langue=="ang" :
+           from dicoCasEnToCata import dicoCasEnToCata as dicoCasToCata
+        else :
+           from dicoCasFrToCata import dicoCasFrToCata as dicoCasToCata
+        self.dicoCasToCata=dicoCasToCata
+        
         
          
         
    def traite_entite(self,e):
-       #print "_______________"
-       #print e
-       #print e.nom
        boolIn=0
-       for (nomFils, fils) in e.entites.items() :
+       for (nomFils, fils) in list(e.entites.items()) :
           self.dicoMC[nomFils]=fils
           self.traite_entite(fils)
           boolIn=1
@@ -360,6 +364,7 @@ class READERCATA:
                 moi=moi.pere
           liste.append((moi.nom,moi))
           self.dicoInverse[e.nom]=liste
+          self.dicoInverse[tr(e.nom)]=liste
 
    def cree_rubrique(self,e,dico, niveau):
        from Accas import A_BLOC
@@ -367,8 +372,8 @@ class READERCATA:
        #if niveau != 0 :
        #    if isinstance(e,A_BLOC.BLOC): print decale, e.condition 
        #    else :                           print decale, e. nom  
-       for (nom, fils) in e.entites.items() :
-           if  fils.entites.items() != [] : self.cree_rubrique(fils,dico,niveau+1)
+       for (nom, fils) in list(e.entites.items()) :
+           if  list(fils.entites.items()) != [] : self.cree_rubrique(fils,dico,niveau+1)
            #else : print (niveau+1)*"   ", nom