From f0bbe148a49f22ef2e175557e3a2bb7aba561dbb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9?= Date: Thu, 29 Apr 2010 15:23:45 +0200 Subject: [PATCH] -Handle close view --- .../daEficasWrapper/datassimEficasWrapper.py | 18 ++++- .../daGUI/daEficasWrapper/eficasWrapper.py.in | 17 ++++- src/daSalome/daGUI/daGuiImpl/datassimCase.py | 4 +- .../daGUI/daGuiImpl/datassimGuiManager.py | 76 +++++++++++++++++-- 4 files changed, 98 insertions(+), 17 deletions(-) diff --git a/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py b/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py index 6bf06f4..422a044 100644 --- a/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py +++ b/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py @@ -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): diff --git a/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in b/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in index 3b62d74..b7c547c 100644 --- a/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in +++ b/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in @@ -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) diff --git a/src/daSalome/daGUI/daGuiImpl/datassimCase.py b/src/daSalome/daGUI/daGuiImpl/datassimCase.py index c6c9d88..7814e7b 100644 --- a/src/daSalome/daGUI/daGuiImpl/datassimCase.py +++ b/src/daSalome/daGUI/daGuiImpl/datassimCase.py @@ -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) diff --git a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py index af316ae..e7ac721 100644 --- a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py @@ -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 ! -- 2.39.2