From e34fc7520119fff6565495a25fa405c385f1b24c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Ribes?= Date: Wed, 23 Feb 2011 17:45:31 +0100 Subject: [PATCH] Bouton Open + gestion de l'ouverture multiple --- .../daEficasWrapper/adaoEficasWrapper.py | 194 +++++++++--------- .../daGUI/daGuiImpl/adaoGuiManager.py | 53 +++-- 2 files changed, 137 insertions(+), 110 deletions(-) diff --git a/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py b/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py index b64544c..b477086 100644 --- a/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py +++ b/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py @@ -44,9 +44,6 @@ class AdaoEficasWrapper(eficasSalome.MyEficas): ADAO_INSTALL_DIR = my_path + "/../daEficas" sys.path[:0]=[ADAO_INSTALL_DIR] - self.__myCallbackId = {} - self.__close_editor = None - self.__file_open_name = "" self.__parent = parent def init_gui(self): @@ -54,14 +51,16 @@ class AdaoEficasWrapper(eficasSalome.MyEficas): eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO") self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged) + def addJdcInSalome(self, jdcPath): + debug("addJdcInSalome is called " + str(jdcPath)) + # On gere nous meme l'etude + pass - # On réouvre tous les fichiers comm - # On fait une copie pour ne pas tomber dans une boucle infinie - # Deprecated - # Normalement on ne ferme plus le GUI donc on ne passe plus par là - save_CallbackId = self.__myCallbackId.copy() - for editor, myCallbackId in save_CallbackId.iteritems(): - self.notifyObserver(EficasEvent.EVENT_TYPES.REOPEN, callbackId=myCallbackId) +####### +# +# Gestion des évènements provenant des widgets QT d'Eficas +# +####### def tabChanged(self, index): debug("tabChanged " + str(index)) @@ -70,39 +69,106 @@ class AdaoEficasWrapper(eficasSalome.MyEficas): if index in self.viewmanager.dict_editors.keys(): self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index]) - def addJdcInSalome( self, jdcPath ): - # On gere nous meme l'etude - pass +####### +# +# Méthodes gérant les boutons dans SALOME +# +####### + +# Rq: Utilisation de la méthode str() pour passer d'un Qstring à un string def adaofileNew(self, adao_case): - qtEficas.Appli.fileNew(self) + qtEficas.Appli.fileNew(self) + index = self.viewmanager.myQtab.currentIndex() + adao_case.name = str(self.viewmanager.myQtab.tabText(index)) + adao_case.eficas_editor = self.viewmanager.dict_editors[index] + self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case) + + def adaoFileSave(self, adao_case): + + ok = qtEficas.Appli.fileSave(self) + if ok: index = self.viewmanager.myQtab.currentIndex() - adao_case.name = str(self.viewmanager.myQtab.tabText(index)) # Utilisation de str() pour passer d'un Qstring à un string + adao_case.name = str(self.viewmanager.myQtab.tabText(index)) + adao_case.filename = str(self.viewmanager.dict_editors[index].fichier) adao_case.eficas_editor = self.viewmanager.dict_editors[index] - self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case) + self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case) - def openEmptyCase(self, callbackId): - qtEficas.Appli.fileNew(self) - self.removeCallbackId(callbackId) - self.setCallbackId(callbackId) + def adaoFileSaveAs(self, adao_case): - def adaoFileSave(self, adao_case): + ok = qtEficas.Appli.fileSaveAs(self) + if ok: + index = self.viewmanager.myQtab.currentIndex() + adao_case.name = str(self.viewmanager.myQtab.tabText(index)) + adao_case.filename = str(self.viewmanager.dict_editors[index].fichier) + adao_case.eficas_editor = self.viewmanager.dict_editors[index] + self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case) - ok = qtEficas.Appli.fileSave(self) - if ok: + def adaoFileOpen(self, adao_case): + + tab_number = self.viewmanager.myQtab.count() + ok = self.viewmanager.handleOpen() + if ok: + # On regarde si c'est un nouveau editeur + if self.viewmanager.myQtab.count() > tab_number: index = self.viewmanager.myQtab.currentIndex() - adao_case.name = str(self.viewmanager.myQtab.tabText(index)) # Utilisation de str() pour passer d'un Qstring à un string - adao_case.eficas_editor = self.viewmanager.dict_editors[index] + adao_case.name = str(self.viewmanager.myQtab.tabText(index)) adao_case.filename = str(self.viewmanager.dict_editors[index].fichier) - self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case) + adao_case.eficas_editor = self.viewmanager.dict_editors[index] + self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN, callbackId=adao_case) - def fileSaveAs(self): +####### +# +# Méthodes auxiliares de gestion du GUI Eficas pour synchronisation +# avec la partie GUI de SALOME +# +####### + + def selectCase(self, editor): + rtn = False + for indexEditor in self.viewmanager.dict_editors.keys(): + if editor is self.viewmanager.dict_editors[indexEditor]: + self.viewmanager.myQtab.setCurrentIndex(indexEditor) + rtn = True + break + return rtn + + + + +####### +# +# Méthodes secondaires permettant de gérer les observeurs du +# GUI d'Eficas +# +####### + + def addObserver(self, observer): """ - @overload + In fact, only one observer may be defined for the moment. """ - qtEficas.Appli.fileSaveAs(self) - self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE) + try: + observer.processEficasEvent + except: + raise DevelException("the argument should implement the function processEficasEvent") + self.__observer = observer + + def notifyObserver(self, eventType, callbackId=None): + eficasEvent = EficasEvent(eventType, callbackId) + self.__observer.processEficasEvent(self, eficasEvent) + + +####### +# +# Deprecated code +# +####### + + def openEmptyCase(self, callbackId): + qtEficas.Appli.fileNew(self) + self.removeCallbackId(callbackId) + self.setCallbackId(callbackId) def getCaseName(self): if self.__close_editor is None: @@ -134,30 +200,10 @@ class AdaoEficasWrapper(eficasSalome.MyEficas): self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN) self.__file_open_name = "" - def fileOpen(self): - """ - @overload - """ - fichier = QFileDialog.getOpenFileName(self, - self.trUtf8('Ouvrir Fichier'), - self.CONFIGURATION.savedir, - self.trUtf8('JDC Files (*.comm);;''All Files (*)')) - if fichier.isNull(): return - self.__file_open_name = fichier - self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN) - self.__file_open_name = "" def getOpenFileName(self): return str(self.__file_open_name) - def selectCase(self, editor): - rtn = False - for indexEditor in self.viewmanager.dict_editors.keys(): - if editor is self.viewmanager.dict_editors[indexEditor]: - self.viewmanager.myQtab.setCurrentIndex(indexEditor) - rtn = True - break - return rtn def fileClose(self): """ @@ -190,51 +236,3 @@ class AdaoEficasWrapper(eficasSalome.MyEficas): else: return 0 - # ========================================================================== - # Function for the notification interface between an EficasWrapper an an - # EficasObserver. - - # Association de l'objet editor avec le callbackId - def setCallbackId(self, callbackId): - index = self.viewmanager.myQtab.currentIndex() - self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId - - def removeCallbackId(self, callbackId): - key_to_remove = None - print callbackId - for k, v in self.__myCallbackId.iteritems(): - print k, v - if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID(): - key_to_remove = k - if key_to_remove is not None: - del self.__myCallbackId[key_to_remove] - else: - print "Oups - cannot find callbackId" - - def getCallbackId(self): - if self.__close_editor is None: - index = self.viewmanager.myQtab.currentIndex() - return self.__myCallbackId[self.viewmanager.dict_editors[index]] - else: - return self.__myCallbackId[self.__close_editor] - - def addObserver(self, observer): - """ - In fact, only one observer may be defined for the moment. - """ - try: - observer.processEficasEvent - except: - raise DevelException("the argument should implement the function processEficasEvent") - self.__observer = observer - - def notifyObserver(self, eventType, callbackId=None): - if eventType != EficasEvent.EVENT_TYPES.OPEN: - 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/adaoGuiManager.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py index 8f94a94..4d9e525 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py @@ -81,7 +81,7 @@ class AdaoCaseManager(EficasObserver): def __init__(self): # Création d'un dictionnaire de cas - # Key == nom du cas + # Key == ref objet editor eficas (on est sur qu'elle est unique, cas duplication) # Value == objet AdaoCase() self.cases = {} @@ -131,7 +131,7 @@ class AdaoCaseManager(EficasObserver): # Gestion de la sélection entre le GUI d'Eficas # et l'arbre d'étude de SALOME # -###### +####### # Depuis l'étude SALOME def currentSelectionChanged(self): @@ -141,7 +141,7 @@ class AdaoCaseManager(EficasObserver): """ adaoLogger.debug("currentSelectionChanged") salomeStudyItem = adaoGuiHelper.getSelectedItem() - for case_name, adao_case in self.cases.iteritems(): + for case_editor, adao_case in self.cases.iteritems(): if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID(): self.eficas_manager.selectCase(adao_case.eficas_editor) break @@ -153,8 +153,8 @@ class AdaoCaseManager(EficasObserver): et la selection dans l'étude SALOME """ editor = eficasEvent.callbackId - for case_name, adao_case in self.cases.iteritems(): - if adao_case.eficas_editor is editor: + for case_editor, adao_case in self.cases.iteritems(): + if case_editor is editor: adaoGuiHelper.selectItem(adao_case.salome_study_item.GetID()) break @@ -176,7 +176,7 @@ class AdaoCaseManager(EficasObserver): # 1: la fonction newAdaoCase est appelée par le GUI SALOME # 2: la fonction _processEficasNewEvent est appelée par le manager EFICAS # -###### +####### def newAdaoCase(self): adaoLogger.debug("Création d'un nouveau cas adao") @@ -194,15 +194,33 @@ class AdaoCaseManager(EficasObserver): adao_case.salome_study_id = salomeStudyId adao_case.salome_study_item = salomeStudyItem # Ajout du cas - self.cases[adao_case.name] = adao_case + self.cases[adao_case.eficas_editor] = adao_case + +####### +# +# Gestion de l'ouverture d'un cas +# 1: la fonction openAdaoCase est appelée par le GUI SALOME +# 2: la fonction _processEficasOpenEvent est appelée par le manager EFICAS +# +####### + +# Rq: l'ouverture d'un cas adao est un cas particulier de la création d'un cas adao + + def openAdaoCase(self): + adaoLogger.debug("Ouverture d'un cas adao") + self.eficas_manager.adaoFileOpen(AdaoCase()) + + def _processEficasOpenEvent(self, eficasWrapper, eficasEvent): + self._processEficasNewEvent(eficasWrapper, eficasEvent) ####### # # Gestion de la sauvegarde d'un cas # 1: la fonction saveAdaoCase est appelée par le GUI SALOME +# 1 bis: la fonction saveasAdaoCase est appelée par le GUI SALOME # 2: la fonction _processEficasSaveEvent est appelée par le manager EFICAS # -###### +####### def saveAdaoCase(self): adaoLogger.debug("Sauvegarde du cas s'il y a modification") @@ -215,6 +233,17 @@ class AdaoCaseManager(EficasObserver): self.eficas_manager.adaoFileSave(adao_case) break + def saveasAdaoCase(self): + adaoLogger.debug("Sauvegarde du cas s'il y a modification (version save as)") + # A priori, l'utilisateur s'attend à sauvegarder le cas qui est ouvert + # dans le GUI d'Eficas + self.harmonizeSelectionFromEficas() + salomeStudyItem = adaoGuiHelper.getSelectedItem() + for case_name, adao_case in self.cases.iteritems(): + if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID(): + self.eficas_manager.adaoFileSaveAs(adao_case) + break + def _processEficasSaveEvent(self, eficasWrapper, eficasEvent): adao_case = eficasEvent.callbackId # On met à jour l'étude @@ -227,10 +256,10 @@ class AdaoCaseManager(EficasObserver): ####### # -# Méthodes secondaire permettant de rediriger les évènements +# Méthodes secondaires permettant de rediriger les évènements # de SALOME et d'Eficas vers les bonnes méthodes de la classe # -###### +####### # Gestion des évènements venant du manager Eficas __processOptions={ @@ -239,8 +268,8 @@ class AdaoCaseManager(EficasObserver): EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent", EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent", EficasEvent.EVENT_TYPES.OPEN : "_processEficasOpenEvent", - EficasEvent.EVENT_TYPES.REOPEN : "_processEficasReOpenEvent", - EficasEvent.EVENT_TYPES.TABCHANGED : "_processEficasTabChanged" + EficasEvent.EVENT_TYPES.TABCHANGED : "_processEficasTabChanged", + EficasEvent.EVENT_TYPES.REOPEN : "_processEficasReOpenEvent" } def processEficasEvent(self, eficasWrapper, eficasEvent): -- 2.39.2