]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/monIncludePanel.py
Salome HOME
CCAR: merge de la version 1.14 dans la branche principale
[tools/eficas.git] / InterfaceQT4 / monIncludePanel.py
1 # -*- coding: utf-8 -*-
2 #            CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
9 #
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 #
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
18 #
19 #
20 # ======================================================================
21 # Modules Python
22 # Modules Eficas
23
24 import os,traceback,sys
25 from qtCommun import QTPanel
26 from qtCommun import QTPanelTBW1
27 from qtCommun import QTPanelTBW2
28 from qtCommun import QTPanelTBW3
29 from PyQt4.QtGui import *
30 from PyQt4.QtCore import *
31
32 from  desInclude import Ui_DInc1
33 import convert
34
35 class DInc(Ui_DInc1,QDialog):
36    def __init__(self,parent ,modal ) :
37        QDialog.__init__(self,parent)
38        if hasattr(parent,"leLayout"):
39           parent.leLayout.removeWidget(parent.leLayout.widgetActive)
40           parent.leLayout.widgetActive.close()
41           parent.leLayout.addWidget(self)
42           parent.leLayout.widgetActive=self
43        else:
44           parent.partieDroite=QWidget()
45           parent.leLayout=QGridLayout(parent.partieDroite)
46           parent.leLayout.addWidget(self)
47           parent.addWidget(parent.partieDroite)
48           parent.leLayout.widgetActive=self
49        self.setupUi(self)
50
51
52
53 # Import des panels
54
55 class MonIncludePanel(DInc,QTPanelTBW1,QTPanelTBW2,QTPanelTBW3):
56   """
57   Classe définissant le panel associé aux mots-clés qui demandent
58   à l'utilisateur de choisir une seule valeur parmi une liste de valeurs
59   discrètes
60   """
61   def __init__(self,node, parent = None,name = None,fl = 0):
62         #print "MonIncludePanel"
63         DInc.__init__(self,parent,fl)
64         QTPanel.__init__(self,node,parent)
65         QTPanelTBW2.__init__(self,node,parent)
66         QTPanelTBW1.__init__(self,node,parent)
67         self.connecterSignaux()
68
69         self.node=node
70         if not hasattr(self.node.item.object,'fichier_unite'):
71            self.pageBad()
72         else:
73            self.pageOk()
74
75   def pageOk(self):
76         self.TWChoix.removeTab(3)
77         self.TWChoix.setCurrentIndex(2)
78         self.LENomFichier.setText(self.node.item.object.fichier_ini)
79
80
81   def pageBad(self) :
82         self.TWChoix.removeTab(2)
83         self.TWChoix.setCurrentIndex(2)
84
85   def BBrowsePressed(self):
86       print self.node.makeEdit
87       self.node.makeEdit()
88
89   def BOkIncPressed (self):
90       self.LENomFichReturnPressed()
91
92   def LENomFichReturnPressed(self):
93         nomFichier=str(self.LENomFichier.text())
94         if not os.path.isfile(nomFichier) :
95            commentaire = "Fichier introuvable"
96            self.Commentaire.setText(QString(commentaire))
97            self.editor.affiche_infos(commentaire)
98            return
99
100         text=self.convert_file(nomFichier)
101
102         # Si probleme a la lecture-conversion on arrete le traitement
103         if not text:
104            return
105
106         try :
107            self.node.item.object.change_fichier_init(nomFichier,text)
108            commentaire = "Fichier modifie  : " + self.node.item.get_nom()
109            self.Commentaire.setText(QString(commentaire))
110            self.editor.affiche_infos(commentaire)
111         except: 
112            l=traceback.format_exception_only("Fichier invalide",sys.exc_info()[1])
113            QMessageBox.critical( self, "Erreur fatale au chargement du fichier Include", l[0])
114            commentaire = "Fichier invalide" 
115            self.Commentaire.setText(QString(commentaire))
116            self.editor.affiche_infos(commentaire)
117            return
118
119
120   def convert_file(self,file):
121        """
122          Methode pour convertir le fichier file dans le format courant
123        """
124        format=self.editor.format_fichier
125        text=None
126        if convert.plugins.has_key(format):
127           # Le convertisseur existe on l'utilise
128           p=convert.plugins[format]()
129           p.readfile(file)
130           text=p.convert('execnoparseur')
131        else :
132             commentaire = "Impossible de lire le fichier : Format inconnu"
133             self.Commentaire.setText(QString(commentaire))
134             self.editor.affiche_infos(commentaire)
135        return text
136
137
138   def BChangeFilePressed(self):
139       userDir=os.path.expanduser("~/Eficas_install/")
140       fn = QFileDialog.getOpenFileName(self.node.appliEficas,
141                 self.node.appliEficas.trUtf8('Fichier Include'),
142                 self.node.appliEficas.trUtf8('All Files (*);;''JDC Files (*.comm);;'))
143
144       if fn.isNull():
145          return
146
147       fn = os.path.abspath((unicode(fn)))
148       self.LENomFichier.setText(fn)
149       self.LENomFichReturnPressed()
150
151   def connecterSignaux(self):
152         self.connect(self.LBNouvCommande,SIGNAL("doubleClicked(QListBoxItem*)"),self.LBNouvCommandeClicked)
153         self.connect(self.LEFiltre,SIGNAL("textChanged(const QString&)"),self.LEFiltreTextChanged)
154         self.connect(self.LEFiltre,SIGNAL("returnPressed()"),self.LEfiltreReturnPressed)
155         self.connect(self.bSup,SIGNAL("pressed()"),self.BSupPressed)
156         self.connect(self.bOk,SIGNAL("clicked()"),self.BOkPressed)
157         self.connect(self.RBGroupe,SIGNAL("clicked()"),self.BuildTabCommand)
158         self.connect(self.RBalpha,SIGNAL("clicked()"),self.BuildTabCommand)
159         self.connect(self.bHelp,SIGNAL("clicked()"),self.ViewDoc)
160         self.connect(self.BNext,SIGNAL("pressed()"),self.BNextPressed)
161         self.connect(self.BBrowse,SIGNAL("clicked()"),self.BBrowsePressed)
162         try :
163            self.connect(self.BChangeFile,SIGNAL("clicked()"),self.BChangeFilePressed)
164            self.connect(self.LENomFichier,SIGNAL("returnPressed()"),self.LENomFichReturnPressed)
165         except :
166            pass
167
168   def ViewDoc(self):
169       QTPanel.ViewDoc(self)
170
171   def BSupPressed(self):
172       QTPanel.BSupPressed(self)
173
174   def BOkPressed(self):
175       QTPanel.BOkPressed(self)
176
177   def BNextPressed(self):
178       QTPanelTBW2.BNextPressed(self)
179
180   def BuildTabCommand(self):
181       QTPanelTBW2.BuildLBNouvCommande(self)
182
183   def LEFiltreTextChanged(self):
184       QTPanelTBW2.LEFiltreTextChanged(self)
185
186   def LEfiltreReturnPressed(self):
187       QTPanelTBW2.LEfiltreReturnPressed(self)
188
189   def LBNouvCommandeClicked(self):
190       QTPanelTBW2.LBNouvCommandeClicked(self)
191
192   def LENomConceptReturnPressed(self):
193       QTPanelTBW3.LENomConceptReturnPressed(self)
194