Salome HOME
optim eciture
[tools/eficas.git] / InterfaceQT4 / viewManager.py
index e2fcece0b9b0e6a982743786a1b52b2ec3024ae4..e75c8a9bb875e31bb68d88dd686f2da51785cd16 100644 (file)
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-import os, string
-from PyQt4.QtGui  import *
-from PyQt4.QtCore import *
+from __future__ import absolute_import
+try :
+   from builtins import str
+   from builtins import object
+except : pass
+
+import os
 from Extensions.i18n import tr
+import six
+from  PyQt5.QtWidgets  import QFileDialog, QMessageBox
+from  PyQt5.QtCore     import QFileInfo
 
 DictExtensions= {"MAP" : ".map"}
-class MyTabview:
+class MyTabview(object):
 
    def __init__(self,appliEficas):
        self.appliEficas=appliEficas
@@ -37,13 +44,13 @@ class MyTabview:
        self.doubles = {}
 
        self.myQtab = self.appliEficas.myQtab
-       self.myQtab.connect(self.myQtab, SIGNAL('tabCloseRequested(int)'), self.closeTab)
-       if self.appliEficas.multi== True:
-          self.myQtab.connect(self.myQtab,SIGNAL("currentChanged(int)"),self.indexChanged)
+
+       self.myQtab.currentChanged.connect(self.indexChanged)
+       self.myQtab.tabCloseRequested.connect(self.closeTab)
         
    def indexChanged(self):
        index=self.myQtab.currentIndex()
-       if  self.dict_editors.has_key(index):
+       if index in self.dict_editors:
            editor=self.dict_editors[index]
            self.appliEficas.CONFIGURATION=editor.CONFIGURATION
            self.appliEficas.code=editor.CONFIGURATION.code
@@ -53,11 +60,11 @@ class MyTabview:
    def handleOpen(self,fichier=None,patron=0,units=None):
        result = None
        if fichier is None:
-            if self.appliEficas.multi==True : 
+            if self.appliEficas.demande==True : 
                self.appliEficas.definitCode(None,None)
                if self.appliEficas.code == None:return
             
-            if DictExtensions.has_key(self.appliEficas.code) :
+            if self.appliEficas.code in DictExtensions:
                chaine="JDC (*"+DictExtensions[self.appliEficas.code]+");;"
                extensions=tr(chaine+ "All Files (*)")
             else :
@@ -67,10 +74,9 @@ class MyTabview:
                         tr('Ouvrir Fichier'),
                         self.appliEficas.CONFIGURATION.savedir,
                          extensions)
-            if fichier.isNull(): 
-              return result
-       fichier = os.path.abspath(unicode(fichier))
-       ulfile = os.path.abspath(unicode(fichier))
+            fichier=fichier[0]
+       fichier = os.path.abspath(six.text_type(fichier))
+       ulfile = os.path.abspath(six.text_type(fichier))
        self.appliEficas.CONFIGURATION.savedir=os.path.split(ulfile)[0]
        self.appliEficas.addToRecentList(fichier)
        maPage=self.getEditor( fichier,units=units)
@@ -129,6 +135,13 @@ class MyTabview:
        editor=self.dict_editors[index]
        editor.handleRechercher()
 
+   def handleRechercherDsCatalogue(self):
+       #print "passage dans handleRechercher"
+       index=self.myQtab.currentIndex()
+       if index < 0 : return
+       editor=self.dict_editors[index]
+       editor.handleRechercherDsCatalogue()
+
    def handleDeplier(self):
        index=self.myQtab.currentIndex()
        if index < 0 : return
@@ -163,7 +176,7 @@ class MyTabview:
        editor.handleSupprimer()
 
    def newEditor(self,include=0):
-       if self.appliEficas.multi==True : 
+       if self.appliEficas.demande==True : 
            self.appliEficas.definitCode(None,None)
            if self.appliEficas.code == None:return
        maPage=self.getEditor(include=include)
@@ -176,10 +189,31 @@ class MyTabview:
        if index < 0 : return
        self.dict_editors[index].viewJdcSource()
 
+   def ouvreArbre(self):
+       index=self.myQtab.currentIndex()
+       if index < 0 : return
+       self.dict_editors[index].ouvreArbre()
+
+   def fermeArbre(self):
+       index=self.myQtab.currentIndex()
+       if index < 0 : return
+       self.dict_editors[index].fermeArbre()
+
+   def ajoutCommentaire(self):
+       index=self.myQtab.currentIndex()
+       if index < 0 : return
+       editor=self.dict_editors[index]
+       editor.ajoutCommentaire()
+
+   def handleViewJdcRegles(self):
+       index=self.myQtab.currentIndex()
+       if index < 0 : return
+       self.dict_editors[index].viewJdcRegles()
+
    def handlegestionParam(self):
        index=self.myQtab.currentIndex()
        if index < 0 : 
-          QMessageBox.warning( self.appliEficas,tr( "Creation Paramètre indisponible"),tr( "les paramètres sont liés à un jeu de données"))
+          QMessageBox.warning( self.appliEficas,tr(u"Creation Parametre indisponible"),tr(u"les parametres sont lies a un jeu de donnees"))
           return
        self.dict_editors[index].gestionParam()
 
@@ -197,33 +231,38 @@ class MyTabview:
        index=self.myQtab.currentIndex()
        if index < 0 : return
        editor=self.dict_editors[index]
-       if editor in self.doubles.keys() :
+       if editor in self.doubles :
            QMessageBox.warning(
                      None,
                      tr("Fichier Duplique"),
-                     tr("Le fichier ne sera pas sauvegarde."),
-                     tr("&Annuler"))
+                     tr("Le fichier ne sera pas sauvegarde."),)
            return
        ok, newName = editor.saveFile()
        if ok :
-           fileName=os.path.basename(unicode(newName))
+           fileName=os.path.basename(six.text_type(newName))
            self.myQtab.setTabText(index,fileName)
        return ok
 
+   def saveLegerCurrentEditor(self):
+       index=self.myQtab.currentIndex()
+       if index < 0 : return
+       editor=self.dict_editors[index]
+       ok, newName = editor.saveFileLeger()
+       return ok
+
    def sauveLigneCurrentEditor(self):
        index=self.myQtab.currentIndex()
        if index < 0 : return
        editor=self.dict_editors[index]
-       if editor in self.doubles.keys() :
+       if editor in self.doubles :
            QMessageBox.warning(
                      None,
                      tr("Fichier Duplique"),
-                     tr("Le fichier ne sera pas sauvegarde."),
-                     tr("&Annuler"))
+                     tr("Le fichier ne sera pas sauvegarde."),)
            return
        ok, newName = editor.sauveLigneFile()
        if ok :
-           fileName=os.path.basename(unicode(newName))
+           fileName=os.path.basename(six.text_type(newName))
            self.myQtab.setTabText(index,fileName)
        return ok
 
@@ -234,9 +273,9 @@ class MyTabview:
        oldName=editor.fichier
        ok,newName = editor.saveFileAs()
        if ok :
-           fileName=os.path.basename(unicode(newName))
+           fileName=os.path.basename(six.text_type(newName))
            self.myQtab.setTabText(index,fileName)
-       if editor in self.doubles.keys():
+       if editor in self.doubles :
           if oldName != newName :
              del self.doubles[editor]
        return ok
@@ -256,19 +295,21 @@ class MyTabview:
        newWin = 0
        double = None
        indexEditor=0
-       for indexEditor in self.dict_editors.keys():
+       for indexEditor in self.dict_editors :
            editor=self.dict_editors[indexEditor]
            if self.samepath(fichier, editor.getFileName()):
-              abort = QMessageBox.warning(self.appliEficas,
-                        tr("Fichier"),
-                        tr("Le fichier <b>%s</b> est deja ouvert.",str(fichier)),
-                        tr("&Duplication"),
-                        tr("&Abort"))
+              msgBox = QMessageBox()
+              msgBox.setWindowTitle(tr("Fichier"))
+              msgBox.setText(tr("Le fichier <b>%s</b> est deja ouvert", str(fichier)))
+              msgBox.addButton(tr("&Duplication"),0)
+              msgBox.addButton(tr("&Abandonner"),1)
+              abort=msgBox.exec_()
               if abort: break
               double=editor
        else :
-            from editor import JDCEditor
+            from .editor import JDCEditor
             editor = JDCEditor(self.appliEficas,fichier, jdc, self.myQtab,units=units,vm = self,include=include)
+
             if double != None : 
                self.doubles[editor]=double
             if editor.jdc: # le fichier est bien un jdc
@@ -291,7 +332,7 @@ class MyTabview:
 #PNPNPNPN --> a affiner
         if fichier is None:
             self.untitledCount += 1
-            self.myQtab.addTab(win, tr("Fichier non encore nommé ", self.untitledCount))
+            self.myQtab.addTab(win, tr("Fichier non encore nomme ", self.untitledCount))
             #self.myQtab.addTab(win, str(self.appliEficas.code))
         else:
             liste=fichier.split('/')
@@ -328,29 +369,29 @@ class MyTabview:
         @return flag indicating successful reset of the dirty flag (boolean)
         """        
         res=1 
-        if (editor.modified) and (editor in self.doubles.keys()) :
-            res = QMessageBox.warning(
-                     None,
-                     tr("Fichier Duplique"),
-                     tr("Le fichier ne sera pas sauvegarde."),
-                     tr(texte), 
-                     tr("&Annuler"))
+        if (editor.modified) and (editor in self.doubles) :
+            msgBox = QMessageBox(None)
+            msgBox.setWindowTitle(tr("Fichier Duplique"))
+            msgBox.setText(tr("Le fichier ne sera pas sauvegarde."))
+            msgBox.addButton(texte,0)
+            msgBox.addButton(tr("&Annuler"),1)
+            res=msgBox.exec_()
             if res == 0 : return 1
             return 2
         if editor.modified:
             fn = editor.getFileName()
-            if fn is None:
-                fn = self.appliEficas.trUtf8('Noname')
-            res = QMessageBox.warning(self.appliEficas, 
-                tr("Fichier Modifie"),
-                tr("Le fichier %s n a pas ete sauvegarde.",str(fn)),
-                tr("&Sauvegarder"),
-                tr(texte),
-                tr("&Annuler") )
+            if fn is None: fn = tr('Noname')
+            msgBox = QMessageBox(None)
+            msgBox.setWindowTitle(tr("Fichier Modifie"))
+            msgBox.setText(tr("Le fichier ne sera pas sauvegarde."))
+            msgBox.addButton(tr("&Sauvegarder"),1)
+            msgBox.addButton(tr("&Quitter sans sauvegarder"),0)
+            res=msgBox.exec_()
+            if res == 2 : res = 1
             if res == 0:
                 (ok, newName) = editor.saveFile()
                 if ok:
-                    fileName=os.path.basename(unicode(newName))
+                    fileName=os.path.basename(six.text_type(newName))
                     index=self.myQtab.currentIndex()
                     self.myQtab.setTabText(index,fileName)
                 return ok