From: Renaud Barate Date: Thu, 1 Jul 2010 14:26:22 +0000 (+0000) Subject: Simplified catalog description management with readercata X-Git-Tag: V2_0~40 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e25e39895d96ce2ca98a81955666b994366491c9;p=modules%2Feficas.git Simplified catalog description management with readercata --- diff --git a/Editeur/catadesc.py b/Editeur/catadesc.py new file mode 100644 index 00000000..ff0d8686 --- /dev/null +++ b/Editeur/catadesc.py @@ -0,0 +1,79 @@ +# -*- 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. +# +# 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. +# +# 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. +# +# +# ====================================================================== + +class CatalogDescription: + + def __init__(self, identifier, cata_file_path, file_format = "python", + default = False, code = None, user_name = None, + selectable = True): + """ + This class can be used to describe an Eficas catalog. + + :type identifier: string + :param identifier: unique identifier for the catalog + + :type cata_file_path: string + :param cata_file_path: path of the file containing the catalog itself + + :type file_format: string + :param file_format: format of the files generated when using this + catalog + + :type default: boolean + :param default: indicate if this catalog is the default one (appear on + the top of the catalogs list) + + :type code: string + :param code: Deprecated. Used to indicate the code associated to this + catalog + + :type user_name: string + :param user_name: name of the catalog as it will appear in the list + + :type selectable: boolean + :param selectable: indicate if this catalog appears in the list. + Setting this parameter to False is useful to keep + old catalogs to edit existing files but to forbid + to use them to create new files. + + """ + self.identifier = identifier + self.cata_file_path = cata_file_path + self.file_format = file_format + self.default = default + self.code = code + if user_name is None: + self.user_name = identifier + else: + self.user_name = user_name + self.selectable = selectable + + @staticmethod + def create_from_tuple(cata_tuple): + print "Warning: Describing a catalog with a tuple is deprecated. " \ + "Please create a CatalogDescription instance directly." + desc = CatalogDescription(code = cata_tuple[0], + identifier = cata_tuple[1], + cata_file_path = cata_tuple[2], + file_format = cata_tuple[3]) + if len(cata_tuple) == 5 and cata_tuple[4] == "defaut": + desc.default = True + return desc diff --git a/InterfaceQT4/monChoixCata.py b/InterfaceQT4/monChoixCata.py index 169d37c0..2c1a7498 100644 --- a/InterfaceQT4/monChoixCata.py +++ b/InterfaceQT4/monChoixCata.py @@ -32,30 +32,23 @@ from PyQt4.QtCore import * class MonChoixCata(Ui_DChoixCata,QtGui.QDialog): """ - Classe définissant le panel associé aux mots-clés qui demandent - à l'utilisateur de choisir une seule valeur parmi une liste de valeurs - discrètes + Classe définissant le panel associé aux mots-clés qui demandent + à l'utilisateur de choisir une seule valeur parmi une liste de valeurs + discrètes """ - def __init__(self,listeCata,readercata, QWparent , name = None,fl = 0): - QtGui.QDialog.__init__(self,QWparent) + def __init__(self, QWparent, listeCata, title = None): + QtGui.QDialog.__init__(self, QWparent) self.setModal(True) self.setupUi(self) - self.listeCata=listeCata - self.readercata=readercata - for cata in self.listeCata : - self.CBChoixCata.insertItem(100,cata) - lab = QString(repr(len(listeCata))) - lab += QString(" versions du catalogue sont disponibles") - self.TLNb.setText(lab) - self.CBChoixCata.setCurrentIndex(0) - self.readercata.version_cata=self.CBChoixCata.currentText() + self.CBChoixCata.addItems(listeCata) + self.TLNb.setText(QString("%d versions du catalogue sont disponibles" % + len(listeCata))) + if title is not None: + self.setWindowTitle(QString.fromUtf8(title)) def on_buttonCancel_clicked(self): QDialog.reject(self) - def on_CBChoixCata_activated(self): - self.readercata.version_cata=self.CBChoixCata.currentText() - def on_buttonOk_clicked(self): QDialog.accept(self) diff --git a/InterfaceQT4/monUniqueBasePanel.py b/InterfaceQT4/monUniqueBasePanel.py index 39892c22..f8590916 100644 --- a/InterfaceQT4/monUniqueBasePanel.py +++ b/InterfaceQT4/monUniqueBasePanel.py @@ -88,6 +88,7 @@ class MonUniqueBasePanel(DUnBase,QTPanel,SaisieValeur): else : self.bParametres.close() type = mc.type[0] + # TODO: Use type properties instead of hard-coded "grno" and "grma" type check enable_salome_selection = self.editor.salome and \ (('grma' in repr(type)) or ('grno' in repr(type)) or (hasattr(type, "enable_salome_selection") and type.enable_salome_selection)) diff --git a/InterfaceQT4/readercata.py b/InterfaceQT4/readercata.py index 174ced8c..7a88e5ad 100644 --- a/InterfaceQT4/readercata.py +++ b/InterfaceQT4/readercata.py @@ -29,9 +29,11 @@ import os,sys,py_compile import traceback import cPickle import re +import types # Modules Eficas from Noyau.N_CR import CR +from Editeur.catadesc import CatalogDescription from Editeur.utils import init_rep_cata_dev import analyse_catalogue @@ -72,9 +74,20 @@ class READERCATA: liste_cata_possibles=[] self.Commandes_Ordre_Catalogue=[] + + all_cata_list = [] for catalogue in self.appliEficas.CONFIGURATION.catalogues: - if catalogue[0] == self.code : - if (self.ssCode == None) or (self.ssCode == catalogue[3]): + if isinstance(catalogue, CatalogDescription): + all_cata_list.append(catalogue) + elif isinstance(catalogue, types.TupleType): + all_cata_list.append(CatalogDescription.create_from_tuple(catalogue)) + else: + print "Catalog description cannot be interpreted: ", catalogue + + # TODO: Remove this filter. Normally, CONFIGURATION should only define the catalogs for this code anyway. + for catalogue in all_cata_list: + if catalogue.code == self.code : + if (self.ssCode == None) or (self.ssCode == catalogue.file_format): liste_cata_possibles.append(catalogue) if len(liste_cata_possibles)==0: @@ -82,34 +95,49 @@ class READERCATA: self.appliEficas.close() if self.appliEficas.salome == 0 : sys.exit(1) + return if self.version_code is not None: # La version a ete fixee for cata in liste_cata_possibles: - if self.version_code == cata[1]: - self.fic_cata = cata[2] - self.appliEficas.format_fichier=cata[3] - elif len(liste_cata_possibles)==1: - self.fic_cata = liste_cata_possibles[0][2] - self.version_code = liste_cata_possibles[0][1] - self.appliEficas.format_fichier=liste_cata_possibles[0][3] - lab=QString("Eficas ") - lab+=QString(self.VERSION_EFICAS) - lab+=QString(" pour ") - lab+=QString(self.code) - lab+=QString(" avec le catalogue ") - lab+=self.version_code - try : - # souci pour les includes et sans Ihm - self.appliEficas.setWindowTitle(lab) - except : - pass + if self.version_code == cata.identifier: + self.fic_cata = cata.cata_file_path + self.appliEficas.format_fichier = cata.file_format else: - # plusieurs catalogues sont disponibles : il faut demander a l'utilisateur - # lequel il veut utiliser ... - self.ask_choix_catalogue() - # On est dans Salome et il faut sortir proprement + cata_choice_list = [] + for cata in liste_cata_possibles: + if cata.selectable: + if cata.default: + cata_choice_list.insert(0, cata) + else : + cata_choice_list.append(cata) + if len(cata_choice_list) == 0: + QMessageBox.critical(self.QWParent, "Import du catalogue", + QString.fromUtf8("Aucun catalogue trouvé")) + self.appliEficas.close() + if self.appliEficas.salome == 0 : + sys.exit(1) + elif len(cata_choice_list) == 1: + self.fic_cata = cata_choice_list[0].cata_file_path + self.version_code = cata_choice_list[0].identifier + self.appliEficas.format_fichier = cata_choice_list[0].file_format + lab=QString("Eficas ") + lab+=QString(self.VERSION_EFICAS) + lab+=QString(" pour ") + lab+=QString(self.code) + lab+=QString(" avec le catalogue ") + lab+=self.version_code + try : + # souci pour les includes et sans Ihm + self.appliEficas.setWindowTitle(lab) + except : + pass + else: + # plusieurs catalogues sont disponibles : il faut demander a l'utilisateur + # lequel il veut utiliser ... + self.ask_choix_catalogue(cata_choice_list) + # On est dans Salome et il faut sortir proprement if self.fic_cata == None : if self.appliEficas.salome == 0 : @@ -205,38 +233,13 @@ class READERCATA: rep_cata = os.path.dirname(self.fic_cata) self.Commandes_Ordre_Catalogue = analyse_catalogue_initial.analyse_catalogue(self.fic_cata) - def ask_choix_catalogue(self): + def ask_choix_catalogue(self, cata_choice_list): """ - Ouvre une fenetre de sélection du catalogue dans le cas oa¹ plusieurs + Ouvre une fenetre de sélection du catalogue dans le cas où plusieurs ont été définis dans Accas/editeur.ini """ - # construction du dictionnaire et de la liste des catalogues - self.dico_catalogues = {} - liste_choix=[] - for catalogue in self.appliEficas.CONFIGURATION.catalogues: - if catalogue[0] == self.code : - self.dico_catalogues[catalogue[1]] = catalogue - if len(catalogue) == 5 : - if catalogue[4]=='defaut' : - liste_choix.insert(0,catalogue[1]) - else : - liste_choix.append(catalogue[1]) - - - lab=QString(self.VERSION_EFICAS) - lab+=QString(" pour ") - lab+=QString(self.code) - lab+=QString(" avec le catalogue ") - - # teste si plusieurs catalogues ou non - if len(liste_choix) == 0: - QMessageBox.critical( self.QWParent, "", QString.fromUtf8("Aucun catalogue déclaré pour %s" %self.code)) - self.appliEficas.close() - if self.appliEficas.salome == 0 : - sys.exit(1) - - # création d'une boite de dialogue modale - widgetChoix=MonChoixCata(liste_choix,self, self.appliEficas, "", True ) + title = getattr(self.appliEficas.CONFIGURATION, "cata_choice_window_title", None) + widgetChoix = MonChoixCata(self.appliEficas, [cata.user_name for cata in cata_choice_list], title) ret=widgetChoix.exec_() lab=QString(self.VERSION_EFICAS) @@ -244,19 +247,19 @@ class READERCATA: lab+=QString(self.code) lab+=QString(" avec le catalogue ") if ret == QDialog.Accepted: - self.version_cata=str(self.version_cata) - self.fic_cata = self.dico_catalogues[self.version_cata][2] + cata = cata_choice_list[widgetChoix.CBChoixCata.currentIndex()] + self.version_cata = cata.identifier + self.fic_cata = cata.cata_file_path self.version_code = self.version_cata - self.appliEficas.format_fichier = self.dico_catalogues[self.version_cata][3] + self.appliEficas.format_fichier = cata.file_format lab+=self.version_cata self.appliEficas.setWindowTitle(lab) #qApp.mainWidget().setCaption(lab) - else : - self.appliEficas.close() + else: + self.appliEficas.close() if self.appliEficas.salome == 0 : sys.exit(0) - def traite_clefs_documentaires(self): try: self.fic_cata_clef=os.path.splitext(self.fic_cata_c)[0]+'_clefs_docu' diff --git a/Noyau/N_VALIDATOR.py b/Noyau/N_VALIDATOR.py index 7a60b914..513f172b 100644 --- a/Noyau/N_VALIDATOR.py +++ b/Noyau/N_VALIDATOR.py @@ -130,7 +130,8 @@ class TypeProtocol(PProtocol): if is_str(obj): return obj elif type_permis == 'Fichier' : import os - if os.path.isfile(obj):return obj + if (len(typ) > 2 and typ[2] == "Sauvegarde") or os.path.isfile(obj): + return obj else : raise ValError("%s n'est pas un fichier valide" % repr(obj)) elif type(type_permis) == types.ClassType or isinstance(type_permis,type): try: