]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
-Handle close view
authorAndré <andre.ribes@edf.fr>
Thu, 29 Apr 2010 13:23:45 +0000 (15:23 +0200)
committerAndré <andre.ribes@edf.fr>
Thu, 29 Apr 2010 13:23:45 +0000 (15:23 +0200)
src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py
src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in
src/daSalome/daGUI/daGuiImpl/datassimCase.py
src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py

index 6bf06f46459fadf722da556cd4ef72cbaaae9d4e..422a0443d1c0f055f436f9be1e12a175272b6838 100644 (file)
@@ -41,6 +41,13 @@ class DatassimEficasWrapper(EficasWrapper):
     def __init__(self, parent, code="DATASSIM"):
         EficasWrapper.__init__(self, parent, code)
 
+    def init_gui(self):
+      EficasWrapper.init_gui(self)
+      print "self.__myCallbackId", self.__myCallbackId
+      save_CallbackId =  self.__myCallbackId.copy()
+      for editor, myCallbackId in save_CallbackId.iteritems():
+        self.notifyObserver(EficasEvent.EVENT_TYPES.REOPEN, callbackId=myCallbackId)
+
     # Association de l'objet editor avec le callbackId
     def setCallbackId(self, callbackId):
       index = self.viewmanager.myQtab.currentIndex()
@@ -120,10 +127,13 @@ class DatassimEficasWrapper(EficasWrapper):
       for editor, myCallbackId in self.__myCallbackId.iteritems():
         if myCallbackId[0] == callbackId[0]:
           if myCallbackId[1].GetID() == callbackId[1].GetID():
-            rtn = True
-            for indexEditor in self.viewmanager.dict_editors.keys():
-              if editor is self.viewmanager.dict_editors[indexEditor]:
-                self.viewmanager.myQtab.setCurrentIndex(indexEditor)
+            try:
+              for indexEditor in self.viewmanager.dict_editors.keys():
+                if editor is self.viewmanager.dict_editors[indexEditor]:
+                  self.viewmanager.myQtab.setCurrentIndex(indexEditor)
+                  rtn = True
+            except:
+              pass
       return rtn
 
     def fileClose(self):
index 3b62d7452a059a523b95bfe81d63e6a398938d7b..b7c547ce143a4c455a7394064f2bc427ca4a594d 100644 (file)
@@ -55,6 +55,7 @@ class EficasEvent:
         'SAVE',
         'DESTROY',
         'OPEN',
+        'REOPEN',
         'NEW'
     ])
 
@@ -109,6 +110,8 @@ class EficasWrapper(qtEficas.Appli):
 
         self.__codetype = code
         self.__jdc = None
+        self.__salome = salome
+        self.__parent = parent
 
         # variables for the notification procedure
         self.__observer  = None
@@ -132,7 +135,12 @@ class EficasWrapper(qtEficas.Appli):
                 print "noversion"
             session.parse( eficasArg )
 
-        qtEficas.Appli.__init__( self,code=code,salome=salome,parent=parent)
+    #    qtEficas.Appli.__init__( self,code=code,salome=salome,parent=parent)
+    def init_gui(self):
+      import InterfaceQT4.readercata
+      if hasattr(InterfaceQT4.readercata,'reader') :
+         del InterfaceQT4.readercata.reader
+      qtEficas.Appli.__init__( self,code=self.__codetype,salome=self.__salome,parent=self.__parent)
 
     def setCodeType(self,code):
         self.__codetype = code
@@ -172,9 +180,12 @@ class EficasWrapper(qtEficas.Appli):
             raise DevelException("the argument should implement the function processEficasEvent")
         self.__observer = observer
 
-    def notifyObserver(self, eventType):
+    def notifyObserver(self, eventType, callbackId=None):
       if eventType != EficasEvent.EVENT_TYPES.NEW and eventType != EficasEvent.EVENT_TYPES.OPEN:
-        eficasEvent = EficasEvent(eventType, self.getCallbackId())
+        if callbackId is None :
+          eficasEvent = EficasEvent(eventType, self.getCallbackId())
+        else:
+          eficasEvent = EficasEvent(eventType, callbackId)
       else:
         eficasEvent = EficasEvent(eventType)
       self.__observer.processEficasEvent(self, eficasEvent)
index c6c9d882ed23003afc4d01a21f73cbdc1cb4bcc5..7814e7b2351b6375b94f3427abb59042da361f60 100644 (file)
@@ -30,10 +30,10 @@ class DatassimCase:
     return self.__name
 
   def set_name(self, name):
-    self.__name = name
+    self.__name = str(name)
 
   def get_filename(self):
     return self.__filename
 
   def set_filename(self, name):
-    self.__filename = name
+    self.__filename = str(name)
index af316aef8c9a7afd1ef4ff9e0af309ce322fd347..e7ac7217edfef8d5c4c3619d0715bb481154d0e2 100644 (file)
@@ -106,6 +106,7 @@ class DatassimGuiActionImpl(EficasObserver):
     cases.
     """
     __dlgEficasWrapper = None
+    __Eficas_viewId = -1
 
     def __init__(self):
         pass
@@ -132,10 +133,28 @@ class DatassimGuiActionImpl(EficasObserver):
             msg = "The requested action is not implemented: " + str(actionId)
             print msg
 
+    def showEficas(self):
+      if self.__Eficas_viewId == -1:
+        print "First showEficas"
+        self.__dlgEficasWrapper.init_gui()
+        self.__Eficas_viewId = SalomePyQt.SalomePyQt().createViewWithMain(self.__dlgEficasWrapper)
+      else:
+        print "myViewId =",  self.__Eficas_viewId
+        print "activeView =", SalomePyQt.SalomePyQt().getActiveView()
+        if SalomePyQt.SalomePyQt().getActiveView() != self.__Eficas_viewId :
+          result_activate = SalomePyQt.SalomePyQt().activateView(self.__Eficas_viewId)
+          if result_activate == False:
+            print "View was close - create a new eficas widget"
+            self.__dlgEficasWrapper.init_gui()
+            self.__Eficas_viewId = SalomePyQt.SalomePyQt().createViewWithMain(self.__dlgEficasWrapper)
+
+
     def newDatassimCase(self):
-      self.__dlgEficasWrapper.displayNew()
+      self.showEficas()
+      self.__dlgEficasWrapper.fileNew()
 
     def openDatassimCase(self):
+      self.showEficas()
       global __cases__
       fichier = QtGui.QFileDialog.getOpenFileName(SalomePyQt.SalomePyQt().getDesktop(),
                                                   self.__dlgEficasWrapper.trUtf8('Ouvrir Fichier'),
@@ -154,25 +173,32 @@ class DatassimGuiActionImpl(EficasObserver):
       self.__dlgEficasWrapper.Openfile(new_case.get_filename())
       callbackId = [salomeStudyId, salomeStudyItem]
       self.__dlgEficasWrapper.setCallbackId(callbackId)
-      self.__dlgEficasWrapper.show()
+      self.showEficas()
       datassimGuiHelper.refreshObjectBrowser()
 
     def editDatassimCase(self):
+      # First we show eficas - all cases are reloaded
       global __cases__
+
+      # Take study item
       salomeStudyId   = datassimGuiHelper.getActiveStudyId()
       salomeStudyItem = datassimGuiHelper.getSelectedItem(salomeStudyId)
       case_key = (salomeStudyId, salomeStudyItem.GetID())
+
+      # ShowEficas, If case is an empty case - case is destroyed by reopen
+      self.showEficas()
       try:
         case = __cases__[case_key]
         # Search if case is in Eficas !
         callbackId = [salomeStudyId, salomeStudyItem]
         case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
+
         # If case is not in eficas Open It !
         if case_open_in_eficas == False:
-          self.__dlgEficasWrapper.Openfile(case.get_filename())
-          callbackId = [salomeStudyId, salomeStudyItem]
-          self.__dlgEficasWrapper.setCallbackId(callbackId)
-          self.__dlgEficasWrapper.show()
+          if case.get_filename() != "":
+            self.__dlgEficasWrapper.Openfile(case.get_filename())
+            callbackId = [salomeStudyId, salomeStudyItem]
+            self.__dlgEficasWrapper.setCallbackId(callbackId)
       except:
         print "Oups - cannot edit case !"
         traceback.print_exc()
@@ -204,7 +230,8 @@ class DatassimGuiActionImpl(EficasObserver):
         EficasEvent.EVENT_TYPES.SAVE  : "_processEficasSaveEvent",
         EficasEvent.EVENT_TYPES.NEW  : "_processEficasNewEvent",
         EficasEvent.EVENT_TYPES.DESTROY  : "_processEficasDestroyEvent",
-        EficasEvent.EVENT_TYPES.OPEN  : "_processEficasOpenEvent"
+        EficasEvent.EVENT_TYPES.OPEN  : "_processEficasOpenEvent",
+        EficasEvent.EVENT_TYPES.REOPEN  : "_processEficasReOpenEvent"
         }
     def processEficasEvent(self, eficasWrapper, eficasEvent):
         """
@@ -221,6 +248,8 @@ class DatassimGuiActionImpl(EficasObserver):
     def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
       global __cases__
       new_case = DatassimCase()
+      case_name = eficasWrapper.getCaseName()
+      new_case.set_name(case_name)
       salomeStudyId   = datassimGuiHelper.getActiveStudyId()
       salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case)
       case_key = (salomeStudyId, salomeStudyItem.GetID())
@@ -229,6 +258,34 @@ class DatassimGuiActionImpl(EficasObserver):
       callbackId = [salomeStudyId, salomeStudyItem]
       self.__dlgEficasWrapper.setCallbackId(callbackId)
 
+    def _processEficasReOpenEvent(self, eficasWrapper, eficasEvent):
+      global __cases__
+      try:
+        callbackId = eficasEvent.callbackId
+        [salomeStudyId, salomeStudyItem] = callbackId
+        case_key = (salomeStudyId, salomeStudyItem.GetID())
+        case = __cases__[case_key]
+        # Search if case is in Eficas !
+        callbackId = [salomeStudyId, salomeStudyItem]
+        print "selectCase"
+        case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
+        # If case is not in eficas Open It !
+        if case_open_in_eficas == False:
+          print "reopen selectCase"
+          if case.get_filename() != "":
+            self.__dlgEficasWrapper.Openfile(case.get_filename())
+            callbackId = [salomeStudyId, salomeStudyItem]
+            self.__dlgEficasWrapper.setCallbackId(callbackId)
+          else:
+            # Since I am an empty case I destroy myself before reloading
+            datassimStudyEditor.removeItem(salomeStudyId, salomeStudyItem)
+            datassimGuiHelper.refreshObjectBrowser()
+            __cases__.pop(case_key)
+            self.__dlgEficasWrapper.fileNew()
+      except:
+        print "Oups - cannot reopen case !"
+        traceback.print_exc()
+
     def _processEficasOpenEvent(self, eficasWrapper, eficasEvent):
       global __cases__
 
@@ -270,8 +327,11 @@ class DatassimGuiActionImpl(EficasObserver):
           case =__cases__[old_case_key]
 
           # Set new informations
-          case.set_filename(file_case_name)
           case.set_name(case_name)
+          if str(case_name).startswith("Untitled"):
+            pass
+          else:
+            case.set_filename(file_case_name)
           datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case)
 
           # Case key changed !