X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=InterfaceQT4%2FviewManager.py;h=e75c8a9bb875e31bb68d88dd686f2da51785cd16;hb=96176d0080e0d4efbd29d98c0df700a64a82acdc;hp=12a9f825f1d77d3079025bc396d42c24f2106b3c;hpb=7e72a676f0cd6fcb60eb9515ba411fdc6dfabc1a;p=tools%2Feficas.git diff --git a/InterfaceQT4/viewManager.py b/InterfaceQT4/viewManager.py index 12a9f825..e75c8a9b 100644 --- a/InterfaceQT4/viewManager.py +++ b/InterfaceQT4/viewManager.py @@ -1,29 +1,37 @@ # -*- coding: utf-8 -*- -# CONFIGURATION MANAGEMENT OF EDF VERSION -# ====================================================================== -# COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG -# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY -# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY -# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR -# (AT YOUR OPTION) ANY LATER VERSION. +# Copyright (C) 2007-2013 EDF R&D # -# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT -# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF -# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU -# GENERAL PUBLIC LICENSE FOR MORE DETAILS. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. # -# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE -# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER, -# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. # +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# ====================================================================== +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from __future__ import absolute_import +try : + from builtins import str + from builtins import object +except : pass -import os, string -from PyQt4.QtGui import * -from PyQt4.QtCore import * +import os +from Extensions.i18n import tr +import six +from PyQt5.QtWidgets import QFileDialog, QMessageBox +from PyQt5.QtCore import QFileInfo -class MyTabview: +DictExtensions= {"MAP" : ".map"} +class MyTabview(object): def __init__(self,appliEficas): self.appliEficas=appliEficas @@ -35,71 +43,143 @@ class MyTabview: self.untitledCount = 0 self.doubles = {} - self.gridLayout = QGridLayout(self.appliEficas.centralWidget()) - self.myQtab = QTabWidget(self.appliEficas.centralWidget()) - self.gridLayout.addWidget(self.myQtab) + self.myQtab = self.appliEficas.myQtab + + self.myQtab.currentChanged.connect(self.indexChanged) + self.myQtab.tabCloseRequested.connect(self.closeTab) + def indexChanged(self): + index=self.myQtab.currentIndex() + if index in self.dict_editors: + editor=self.dict_editors[index] + self.appliEficas.CONFIGURATION=editor.CONFIGURATION + self.appliEficas.code=editor.CONFIGURATION.code + self.appliEficas.setWindowTitle(editor.titre) + self.appliEficas.construitMenu() def handleOpen(self,fichier=None,patron=0,units=None): + result = None if fichier is None: + if self.appliEficas.demande==True : + self.appliEficas.definitCode(None,None) + if self.appliEficas.code == None:return + + if self.appliEficas.code in DictExtensions: + chaine="JDC (*"+DictExtensions[self.appliEficas.code]+");;" + extensions=tr(chaine+ "All Files (*)") + else : + extensions=tr('Fichiers JDC (*.comm);;''Tous les Fichiers (*)') + fichier = QFileDialog.getOpenFileName(self.appliEficas, - self.appliEficas.trUtf8('Ouvrir Fichier'), + tr('Ouvrir Fichier'), self.appliEficas.CONFIGURATION.savedir, - self.appliEficas.trUtf8('JDC Files (*.comm);;''All Files (*)')) - if fichier.isNull(): return - fichier = os.path.abspath(unicode(fichier)) + extensions) + 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) + if maPage: result = maPage + if maPage : self.myQtab.setTabText(self.myQtab.indexOf(maPage),os.path.basename(fichier)) + return result - def handleClose(self,doitSauverRecent = 1): - #print "passage dans handleClose" - #print self.dict_editors + def closeTab(self): + self.handleClose() + + def handleClose(self,doitSauverRecent = 1,texte=tr('&Quitter')): if doitSauverRecent : self.appliEficas.sauveRecents() index=self.myQtab.currentIndex() if index < 0 : return - self.checkDirty(self.dict_editors[index]) + res=self.checkDirty(self.dict_editors[index],texte) + if res == 2 : return 2 # l utilisateur a annule index=self.myQtab.currentIndex() - while index < len(self.dict_editors) -1 : - self.dict_editors[index]=self.dict_editors[index+1] - index = index + 1 + idx=index + while idx < len(self.dict_editors) -1 : + self.dict_editors[idx]=self.dict_editors[idx+1] + idx = idx + 1 del self.dict_editors[len (self.dict_editors) -1] try : del self.doubles[self.dict_editors[index]] except : pass - print self.dict_editors self.myQtab.removeTab(index) + return res - def handleCloseAll(self): + def run(self): + index=self.myQtab.currentIndex() + if index < 0 : return + editor=self.dict_editors[index] + editor.run() + + def saveRun(self): + index=self.myQtab.currentIndex() + if index < 0 : return + editor=self.dict_editors[index] + editor.saveRun() + + def handleCloseAll(self,texte=tr('Quitter')): + res=0 self.appliEficas.sauveRecents() - print "passage dans CloseAll" - print "self.dict_editors", self.dict_editors while len(self.dict_editors) > 0 : self.myQtab.setCurrentIndex(0) - self.handleClose(0) + res=self.handleClose(0,texte) + if res==2 : return res # l utilsateur a annule + return res + def handleRechercher(self): + #print "passage dans handleRechercher" + index=self.myQtab.currentIndex() + if index < 0 : return + 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 + editor=self.dict_editors[index] + editor.handleDeplier() + def handleEditCopy(self): - print "passage dans handleEditCopy" + #print "passage dans handleEditCopy" index=self.myQtab.currentIndex() + if index < 0 : return editor=self.dict_editors[index] editor.handleEditCopy() def handleEditCut(self): - print "passage dans handleEditCut" + #print "passage dans handleEditCut" index=self.myQtab.currentIndex() + if index < 0 : return editor=self.dict_editors[index] editor.handleEditCut() def handleEditPaste(self): - print "passage dans handleEditPaste" + #print "passage dans handleEditPaste" index=self.myQtab.currentIndex() + if index < 0 : return editor=self.dict_editors[index] editor.handleEditPaste() + def handleSupprimer(self): + index=self.myQtab.currentIndex() + if index < 0 : return + editor=self.dict_editors[index] + editor.handleSupprimer() + def newEditor(self,include=0): - print "passage dans newEditor" - maPage=self.getEditor() + if self.appliEficas.demande==True : + self.appliEficas.definitCode(None,None) + if self.appliEficas.code == None:return + maPage=self.getEditor(include=include) def newIncludeEditor(self): self.newEditor(include=1) @@ -109,6 +189,34 @@ 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(u"Creation Parametre indisponible"),tr(u"les parametres sont lies a un jeu de donnees")) + return + self.dict_editors[index].gestionParam() + def handleViewJdcRapport(self): index=self.myQtab.currentIndex() if index < 0 : return @@ -123,17 +231,41 @@ 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, - self.appliEficas.trUtf8("Fichier Duplique"), - self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."), - self.appliEficas.trUtf8("&Annuler")) + tr("Fichier Duplique"), + 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 : + QMessageBox.warning( + None, + tr("Fichier Duplique"), + tr("Le fichier ne sera pas sauvegarde."),) + return + ok, newName = editor.sauveLigneFile() + if ok : + fileName=os.path.basename(six.text_type(newName)) self.myQtab.setTabText(index,fileName) + return ok + def saveAsCurrentEditor(self): index=self.myQtab.currentIndex() @@ -141,12 +273,12 @@ 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 def displayJDC(self,jdc,fn=None): """ @@ -163,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, - self.appliEficas.trUtf8("Fichier"), - self.appliEficas.trUtf8("Le fichier %1 est deja ouvert.").arg(fichier), - self.appliEficas.trUtf8("&Duplication"), - self.appliEficas.trUtf8("&Abort")) + msgBox = QMessageBox() + msgBox.setWindowTitle(tr("Fichier")) + msgBox.setText(tr("Le fichier %s 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 @@ -195,15 +329,17 @@ class MyTabview: return editor def addView(self, win, fichier=None): +#PNPNPNPN --> a affiner if fichier is None: self.untitledCount += 1 - self.myQtab.addTab(win, self.appliEficas.trUtf8("Untitled %1").arg(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('/') txt = liste[-1] if not QFileInfo(fichier).isWritable(): txt = '%s (ro)' % txt - self.myQtab.addTab(win, txt) + self.myQtab.addTab(win,txt ) self.myQtab.setCurrentWidget(win) self.currentEditor=win win.setFocus() @@ -225,43 +361,44 @@ class MyTabview: return 0 - def checkDirty(self, editor): + def checkDirty(self, editor,texte): """ Private method to check dirty status and open a message window. @param editor editor window to check @return flag indicating successful reset of the dirty flag (boolean) """ - - print "checkDirty" - if (editor.modified) and (editor in self.doubles.keys()) : - res = QMessageBox.warning( - None, - self.appliEficas.trUtf8("Fichier Duplique"), - self.appliEficas.trUtf8("Le fichier ne sera pas sauvegarde."), - self.appliEficas.trUtf8("&Quitter"), - self.appliEficas.trUtf8("&Annuler")) + res=1 + 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 0 + return 2 if editor.modified: fn = editor.getFileName() - if fn is None: - fn = self.appliEficas.trUtf8('Noname') - res = QMessageBox.warning(self.appliEficas, - self.appliEficas.trUtf8("Fichier Modifie"), - self.appliEficas.trUtf8("Le fichier %1 n a pas ete sauvegarde.") - .arg(fn), - self.appliEficas.trUtf8("&Sauvegarder"), - self.appliEficas.trUtf8("&Quitter "), - self.appliEficas.trUtf8("&Annuler"), 0, 2) + 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 - elif res == 2: - return 0 - return 1 - + return res + + def handleAjoutGroup(self,listeGroup): + index=self.myQtab.currentIndex() + if index < 0 : return + editor=self.dict_editors[index] + editor.handleAjoutGroup(listeGroup)