]> SALOME platform Git repositories - tools/eficas.git/blob - Editeur/bureau.py
Salome HOME
PN : pour déplacement dans l arbre
[tools/eficas.git] / Editeur / bureau.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 """
22    Ce module contient la classe BUREAU qui gere les JDC ouverts
23 """
24 # Modules Python
25 import os,string,sys
26 import traceback
27 import Pmw
28 from widgets import askopenfilename,asksaveasfilename
29 from widgets import showinfo,askyesno,showerror
30
31 # Modules Eficas
32 import splash
33 import prefs
34 import convert
35 import generator
36 import AIDE
37 from jdcdisplay import JDCDISPLAY
38 from utils import extension_fichier,stripPath,save_in_file
39 from widgets import Fenetre,Ask_Format_Fichier
40 from fenetre_mc_inconnus import fenetre_mc_inconnus
41 from Ihm import CONNECTOR
42
43 import comploader
44
45 class BUREAU:
46    menu_defs=[
47               ('Fichier',[
48                            ('Nouveau','newJDC','<Control-n>'),
49                            ('Ouvrir','openJDC','<Control-o>'),
50                            ('Enregistrer','saveJDC','<Control-e>'),
51                            ('Enregistrer sous','saveasJDC','<Control-s>'),
52                            None,
53                            ('Fermer','closeJDC','<Control-f>'),
54                            ('Quitter','exitEFICAS','<Control-q>'),
55                          ]
56               ),
57               ('Edition',[
58                            ('Copier','copy','<Control-c>'),
59                            ('Couper','cut','<Control-x>'),
60                            ('Coller','paste','<Control-v>'),
61                          ]
62               ),
63               ('Jeu de commandes',[
64                                    ('Rapport de validation','visuCRJDC','<Control-r>'),
65                                    ('Fichier à plat','visu_a_plat','<Control-p>'),
66                                    ('Fichier .py','visuJDC_py'),
67                                    ('Fichier source','visu_txt_brut_JDC','<Control-b>'),
68                                    ('Paramètres Eficas','affichage_fichier_ini'),
69                                    ('Mots-clés inconnus','mc_inconnus'),
70                                   ]
71               ),
72               ('Aide',[
73                         ('Aide EFICAS','aideEFICAS'),
74                       ]
75               ),
76              ]
77
78    button_defs  =      (('New24',"newJDC","Création d'un nouveau fichier",'always'),
79                         ('Open24',"openJDC","Ouverture d'un fichier existant",'always'),
80                         ('Save24',"saveJDC","Sauvegarde du fichier courant",'always'),
81                         ('Fermer24',"closeJDC","Fermeture du fichier courant",'always'),
82                         ('Zoom24',"visuJDC","Visualisation du fichier de commandes",'always'),
83                         None,
84                         ('Copy24',"copy","Copie l'objet courant",'jdc'),
85                         ('Cut24',"cut","Coupe l'objet courant",'jdc'),
86                         ('Paste24',"paste","Colle l'objet copié après l'objet courant",'jdc'),
87                         None,
88                         ('Delete24',"delete","Supprime l'objet courant",'jdc'),
89                         ('Help24',"view_doc","Documentation de l'objet courant",'jdc')
90                        )
91    try:
92       menu_defs=prefs.menu_defs['bureau']
93    except:
94       pass
95    try:
96       button_defs=prefs.button_defs['bureau']
97    except:
98       pass
99
100    def __init__(self,appli,parent):
101       self.parent=parent
102       self.appli=appli
103       if self.appli.test == 0 :
104          splash._splash.configure(text = "Création du bureau")
105       self.nb = Pmw.NoteBook(self.parent,raisecommand=self.selectJDC)
106       self.nb.pack(fill='both',expand=1)
107       self.JDCDisplay_courant=None
108       self.fileName=None
109       self.liste_JDCDisplay=[]
110       comploader.charger_composants()
111       self.cree_cataitem()
112       self.text_reel=""
113       self.initialdir = self.appli.CONFIGURATION.initialdir
114
115    def cree_cataitem(self):
116       """
117           On récupère dans l'appli_composant readercata les variables 
118           qui servent par la suite pour la création des JDC
119       """
120       self.cataitem=self.appli.readercata.cataitem
121       self.cata=self.appli.readercata.cata
122       self.cata_ordonne_dico=self.appli.readercata.cata_ordonne_dico
123       self.code=self.appli.readercata.code
124       self.version_code=self.appli.readercata.version_code
125       self.fic_cata=self.appli.readercata.fic_cata
126
127    def selectJDC(self,event=None):
128       """
129           Cette méthode est appelée chaque fois que l'on sélectionne 
130           l'onglet d'un JDC dans le NoteBook des JDC.
131           Elle permet de stocker dans les variable self.JDC et 
132           self.JDCDisplay_courant les valeurs concernant le JDC courant
133       """
134       if len(self.liste_JDCDisplay) == 0 : return
135       #if self.JDCDisplay_courant : self.JDCDisplay_courant.jdc.unset_context()
136       numero_jdc = self.nb.index(self.nb.getcurselection())
137       self.JDCDisplay_courant.unselect()
138       self.JDCDisplay_courant = self.liste_JDCDisplay[numero_jdc]
139       self.JDC = self.JDCDisplay_courant.jdc
140       self.JDCName = self.JDC.nom
141       self.JDCDisplay_courant.select()
142       #print "selectJDC",numero_jdc,self.JDCDisplay_courant,self.JDCName
143
144
145    def newJDC_include(self,event=None):
146       """
147           Initialise un nouveau JDC vierge
148       """
149       import Extensions.jdc_include
150       JdC_aux=Extensions.jdc_include.JdC_include
151
152       self.appli.statusbar.reset_affichage_infos()
153
154       CONTEXT.unset_current_step()
155       jaux=self.cata[0].JdC(procedure="",appli=self.appli,
156                          cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
157                          rep_mat=self.appli.CONFIGURATION.rep_mat,
158                          )
159       jaux.analyse()
160
161       J=JdC_aux(procedure="",appli=self.appli,
162                          cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
163                          jdc_pere=jaux,
164                          rep_mat=self.appli.CONFIGURATION.rep_mat,
165                          )
166       J.analyse()
167       self.JDCName=J.nom
168       self.fileName=None
169       self.ShowJDC(J,self.JDCName)
170       self.appli.toolbar.active_boutons()
171
172    def newJDC(self,event=None):
173       """
174           Initialise un nouveau JDC include vierge
175       """
176       self.appli.statusbar.reset_affichage_infos()
177
178       CONTEXT.unset_current_step()
179       J=self.cata[0].JdC(procedure="",appli=self.appli,
180                          cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
181                          rep_mat=self.appli.CONFIGURATION.rep_mat,
182                          )
183       J.analyse()
184       self.JDCName=J.nom
185       self.fileName=None
186       self.ShowJDC(J,self.JDCName)
187       self.appli.toolbar.active_boutons()
188
189    def ShowJDC(self,JDC,nom,label_onglet=None,JDCDISPLAY=JDCDISPLAY,enregistre="non"):
190       """
191           Lance l'affichage du JDC cad création du JDCDisplay
192           Rajoute le JDCDisplay à la liste des JDCDisplay si label_onglet == None cad si on crée
193           bien un nouveau JDCDisplay et non si on remplace (renommage de l'onglet)
194       """
195       self.JDC=JDC
196       self.JDCName = self.JDC.nom = nom
197       if label_onglet == None :
198           # On veut un nouvel onglet
199           label_onglet = self.GetLabelJDC()
200           self.nb.add(label_onglet,tab_text = nom,tab_width=20)
201           new = 'oui'
202       else :
203           new = 'non'
204       self.JDCDisplay_courant=JDCDISPLAY(self.JDC,nom,appli=self.appli,parent=self.nb.page(label_onglet))
205       if new == 'oui':
206           self.liste_JDCDisplay.append(self.JDCDisplay_courant)
207       self.JDCDisplay_courant.modified='n'
208       if enregistre != "non" :
209          self.JDCDisplay_courant.fichier=self.fileName
210       else :
211          self.initialdir = self.appli.CONFIGURATION.rep_user
212       self.nb.selectpage(label_onglet)
213       self.nb.setnaturalsize()
214       texte = "Jeu de commandes :" + self.JDCName+" ouvert"
215       CONNECTOR.Connect(JDC,"close",self.onClose,(self.JDCDisplay_courant,))
216       self.appli.affiche_infos(texte)
217
218    def onClose(self,jdcdisplay):
219       #print "onClose",jdcdisplay
220       self.closeJDCDISPLAY(jdcdisplay)
221
222    def closeJDCDISPLAY(self,jdc):
223       """
224         Ferme le jdcdisplay spécifié par l'argument jdc
225       """
226       if jdc is self.JDCDisplay_courant:
227          # on ferme le jdcdisplay courant
228          self.closeSelectedJDC()
229       else:
230          # on ferme un autre jdcdisplay que le courant
231          old_JDCDisplay=self.JDCDisplay_courant
232          old_page=self.nb.getcurselection()
233
234          self.JDCDisplay_courant=jdc
235          self.JDC=jdc.jdc
236          numero_jdc=self.liste_JDCDisplay.index(jdc)
237          self.nb.selectpage(numero_jdc)
238          #print numero_jdc
239       
240          self.closeSelectedJDC()
241          self.JDCDisplay_courant=old_JDCDisplay
242          self.JDC=old_JDCDisplay.jdc
243          self.nb.selectpage(old_page)
244
245    def closeJDC (self,event=None) :
246       """
247           Ferme le JDC associé au JDCDISPLAY selectionné
248       """
249       if self.JDCDisplay_courant :
250          self.JDCDisplay_courant.jdc.close()
251
252    def closeSelectedJDC (self) :
253       """
254       Ferme le JDC courant et détruit l'onglet associé dans le notebook self.nb
255       """
256       if self.JDCDisplay_courant.modified == 'o' :
257           message = "Voulez-vous sauvegarder le jeu de commandes "+self.JDC.nom+" courant ?"
258           reponse = askyesno(title="Sauvegarde du jdc courant",
259                              message=message)
260           if reponse :
261               test = self.saveJDC()
262               if test == 0 :
263                   self.appli.affiche_infos("Sauvegarde impossible")
264                   return
265
266       CONNECTOR.Disconnect(self.JDCDisplay_courant.jdc,"close",self.onClose,(self.JDCDisplay_courant,))
267       self.JDCDisplay_courant.supprime()
268       self.JDCDisplay_courant.jdc.supprime()
269       self.liste_JDCDisplay.remove(self.JDCDisplay_courant)
270       # Active le mecanisme de selection du notebook (selectJDC)
271       self.nb.delete(self.nb.getcurselection())
272
273       try:
274           index = self.nb.index(self.nb.getcurselection())
275           self.JDCDisplay_courant = self.liste_JDCDisplay[index]
276           self.JDC = self.JDCDisplay_courant.jdc
277       except:
278           self.JDC = None
279           self.JDCDisplay_courant = None
280           self.appli.toolbar.inactive_boutons()
281
282    def visuCRJDC(self,event=None):
283       return self.visuCR(mode='JDC')
284
285    def visuCR(self,mode):
286       """
287       Méthode permettant l'affichage du rapport de validation
288       """
289       if mode == 'JDC':
290           if not hasattr(self,'JDC') : return
291           titre="rapport de validation du jeu de commandes courant"
292           cr = self.JDC.report()
293           #self.update_jdc_courant()
294       elif mode == 'CATA':
295           from Noyau.N_CR import CR
296           cr = CR()
297           cr.debut = "Début rapport de validation du catalogue"
298           cr.fin = "Fin rapport de validation du catalogue"
299           titre="rapport de validation du catalogue"
300           if hasattr(self,'cata_ordonne_cr') :
301               cr.add(self.cata_ordonne_cr)
302           if hasattr(self,'cata_dev_ordonne_cr') :
303               cr.add(self.cata_dev_ordonne_cr)
304           for cata in self.cata:
305               if hasattr(cata,'JdC'):
306                   cr.add(cata.JdC.report())
307       texte_cr = str(cr)
308       self.visu_texte_cr = Fenetre(self.appli,titre=titre,texte=texte_cr)
309
310    def openJDC(self,event=None,file=None,units=None,enregistre="oui"):
311       """
312           Demande à l'utilisateur quel JDC existant il veut ouvrir
313       """
314       if self.code == 'ASTER':
315           filetypes = ( ("format "+self.appli.format_fichier.get(), ".com*"),("Tous",'*'))
316       elif self.code == 'HOMARD' :
317           filetypes = ( ("format "+self.appli.format_fichier.get(), ".py"),("Tous",'*'))
318       else:
319           filetypes = ( ("format "+self.appli.format_fichier.get(), ".py"),)
320       if not hasattr(self,'initialdir'):
321          self.initialdir = self.appli.CONFIGURATION.initialdir
322
323       if not file :
324           file = askopenfilename(title="Ouverture d'un fichier de commandes Aster",
325                                  defaultextension=".comm",
326                                  filetypes = filetypes,
327                                  initialdir = self.initialdir)
328       if file :
329           self.fileName = file
330           e=extension_fichier(file)
331           self.JDCName=stripPath(file)
332           self.initialdir = os.path.dirname(os.path.abspath(file))
333       else :
334           return
335
336       format=self.appli.format_fichier.get()
337       # Il faut convertir le contenu du fichier en fonction du format
338       if convert.plugins.has_key(format):
339          # Le convertisseur existe on l'utilise
340          p=convert.plugins[format]()
341          p.readfile(file)
342          text=p.convert('exec',self.appli)
343          if not p.cr.estvide(): 
344             self.appli.affiche_infos("Erreur à la conversion")
345             Fenetre(self.appli,
346                     titre="compte-rendu d'erreurs, EFICAS ne sait pas convertir ce fichier",
347                     texte = str(p.cr)).wait()
348             return
349          if enregistre == "oui" :
350             self.appli.listeFichiers.aOuvert(file)
351       else:
352          # Il n'existe pas c'est une erreur
353          self.appli.affiche_infos("Type de fichier non reconnu")
354          showerror("Type de fichier non reconnu","EFICAS ne sait pas ouvrir ce type de fichier")
355          return
356
357       # On se met dans le repertoire ou se trouve le fichier de commandes
358       # pour trouver les eventuels fichiers include ou autres
359       # localises a cote du fichier de commandes
360       os.chdir(self.initialdir)
361       CONTEXT.unset_current_step()
362       J=self.cata[0].JdC(procedure=text,appli=self.appli,
363                          cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
364                          nom = self.JDCName,
365                          rep_mat=self.appli.CONFIGURATION.rep_mat,
366                          )
367       if units is not None:
368          J.recorded_units=units
369          J.old_recorded_units=units
370
371       J.analyse()
372       txt_exception = J.cr.get_mess_exception()
373       if txt_exception :
374           # des exceptions ont été levées à la création du JDC 
375           # --> on affiche les erreurs mais pas le JDC
376           self.JDC=J
377           self.appli.affiche_infos("Erreur fatale au chargement de %s" %file)
378           if self.appli.test == 0 :
379              showerror("Erreur fatale au chargement d'un fichier",txt_exception)
380       else:
381           self.ShowJDC(J,self.JDCName,enregistre=enregistre)
382           self.appli.toolbar.active_boutons()
383           # si le JDC ne contient rien (vide), on retourne ici
384           if len(self.JDC.etapes) == 0 : return
385           # dans le cas où le JDC est invalide, on affiche son CR
386           if not self.JDC.isvalid():
387              self.appli.top.update()
388              self.visuCR(mode='JDC')
389       # On a ouvert un Patron
390       self.nb.bind_all("<F1>",lambda e,s=self:s.selectArbreDown())
391       self.nb.bind_all("<F2>",lambda e,s=self:s.selectArbreUp())
392
393    def selectArbreDown(self):
394        self.JDCDisplay_courant.tree.tree.canvas.focus_set()
395        self.JDCDisplay_courant.tree.tree.mot_down_force()
396
397    def selectArbreUp(self):
398        self.JDCDisplay_courant.tree.tree.canvas.focus_set()
399        self.JDCDisplay_courant.tree.tree.mot_up_force()
400
401    def GetLabelJDC(self,nb_jdc = 'absent'):
402       """
403       Retourne le label de l'onglet du NoteBook associé au JDC à afficher
404       """
405       if nb_jdc == 'absent':
406           nb_jdc = len(self.nb.pagenames())
407       nb_jdc = nb_jdc+1
408       label_onglet = 'JDC'+`nb_jdc`
409       if label_onglet not in self.nb.pagenames() :
410           return label_onglet
411       else :
412           return self.GetLabelJDC(nb_jdc)
413
414    def saveasJDC(self,event=None):
415       """ 
416            Sauvegarde le JDC courant en demandant impérativement à l'utilisateur de
417            donner le nom du fichier de sauvegarde 
418       """
419       self.saveJDC(echo='oui')
420
421    def saveJDC(self,echo='non'):
422       """ 
423           Sauvegarde le JDC courant.
424           Retourne 1 si la sauvegarde s'est bien faite, 0 sinon.
425           Si echo = 'oui' : interactif (l'utilisateur donne le nom sous lequel il 
426                             veut sauver le JDC
427           Si echo = 'non' : muet (sauvegarde le JDC dans JDC.procedure)
428       """
429       if not hasattr(self,'JDC') : return 0
430       format=self.appli.format_fichier.get()
431       if generator.plugins.has_key(format):
432          # Le generateur existe on l'utilise
433          g=generator.plugins[format]()
434          jdc_formate=g.gener(self.JDC,format='beautifie')
435          if format == 'homard':
436             self.jdc_homard=g.get_homard()
437          if not g.cr.estvide():
438             self.appli.affiche_infos("Erreur à la generation")
439             showerror("Erreur à la generation","EFICAS ne sait pas convertir ce JDC")
440             return
441       else:
442          # Il n'existe pas c'est une erreur
443          self.appli.affiche_infos("Format %s non reconnu" % format)
444          showerror("Format %s non reconnu" % format,"EFICAS ne sait pas convertir le JDC")
445          return
446       self.jdc_fini = string.replace(jdc_formate,'\r\n','\n')
447
448       if echo =='oui' or self.JDCDisplay_courant.fichier == None:
449           return self.asknomsauvegardeJDC()
450       elif self.JDCDisplay_courant.fichier != None :
451           #PN  Ajout --> Salome
452           # Pour sauvegarde dans l etude si lancement depuis salome
453           if self.appli.salome != 0:
454              import eficasEtude 
455              self.appli.salome.rangeInStudy(self.JDCDisplay_courant.fichier)
456              from panelsSalome import SALOME_UNIQUE_BASE_Panel
457              if len(SALOME_UNIQUE_BASE_Panel.dict_fichier_unite) > 0 :
458                 self.appli.salome.creeConfigTxt(self.appli.CONFIGURATION.initialdir,SALOME_UNIQUE_BASE_Panel.dict_fichier_unite)
459              #try :
460              if ( 1 == 1 ) :
461                 import eficasCL
462                 MyCLinit=eficasCL.CLinit()
463                 MyCLinit.traiteCL()
464                 MyCLinit.clean()
465              #except :
466              else :
467                 pass
468           #PN  Fin Ajout --> Salome
469           # le JDC a déjà un nom : on sauvegarde directement sans demander
470           # un autre nom au développeur
471           if not save_in_file(self.JDCDisplay_courant.fichier,self.jdc_fini,self.appli.dir) :
472               showinfo("Erreur","Problème à la sauvegarde du fichier :" + `self.JDCDisplay_courant.fichier`)
473               return 0
474           else :
475               if self.appli.format_fichier.get() == 'homard':
476                   self.save_homard(self.JDCDisplay_courant.fichier,self.jdc_homard)
477               self.JDCDisplay_courant.stop_modif()
478               self.appli.affiche_infos("sauvegarde de "+`self.JDCDisplay_courant.fichier`+" effectuée")
479               return 1
480
481    def asknomsauvegardeJDC(self):
482       """ Demande à l'utilsateur le nom sous lequel il veut sauvegarder le JDC courant """
483       titre = "Sauvegarde d'un fichier de commandes "+self.code
484       if self.code == 'ASTER':
485           defext = ".comm"
486           filtyp = ( ("ASTER", ".comm"),)
487       else :
488           defext = ".py"
489           filtyp = ( (self.code, ".py"),)
490       sauvegarde = asksaveasfilename(title=titre,
491                                      defaultextension=defext,
492                                      filetypes = filtyp,
493                                      initialdir = self.initialdir)
494                             #initialdir = self.appli.CONFIGURATION.initialdir)
495                             #initialdir = self.appli.CONFIGURATION.rep_user)
496       if sauvegarde :
497           # PN ajout --> Salome
498           # Pour sauvegarde dans l etude si lancement depuis salome
499           if self.appli.salome != 0:
500              import eficasEtude 
501              self.appli.salome.rangeInStudy(sauvegarde)
502              from panelsSalome import SALOME_UNIQUE_BASE_Panel
503              if len(SALOME_UNIQUE_BASE_Panel.dict_fichier_unite) > 0 :
504                 self.appli.salome.creeConfigTxt(self.appli.CONFIGURATION.initialdir,SALOME_UNIQUE_BASE_Panel.dict_fichier_unite)
505              #try :
506              if ( 1 == 1 ):
507                 import eficasCL
508                 MyCLinit=eficasCL.CLinit()
509                 MyCLinit.traiteCL()
510                 MyCLinit.clean()
511              #except :
512              else :
513                 pass
514           # PN fin ajout --> Salome
515           if not save_in_file(sauvegarde,self.jdc_fini,None) :
516               showinfo("Erreur","Problème à la sauvegarde du fichier "+`sauvegarde`)
517               return 0
518           else :
519               if self.appli.format_fichier.get() == 'homard':
520                   self.save_homard(sauvegarde,self.jdc_homard)
521               self.JDCDisplay_courant.stop_modif()
522               self.appli.affiche_infos("Sauvegarde effectuée")
523               if sauvegarde != self.JDCDisplay_courant.fichier :
524                   # l'utilisateur a sauvegardé le JDC sous un autre nom
525                   self.JDCDisplay_courant.fichier = sauvegarde
526                   self.JDCName = self.JDC.nom = stripPath(sauvegarde)
527                   self.JDC.changefichier(sauvegarde)
528                   self.changeNomPage()
529               return 1
530       else :
531           return 0
532
533    def changeNomPage(self):
534       """ Change le nom de l'onglet contenant le JDC courant : en fait détruit l'actuel
535           et recrée un autre onglet à la même place avec le bon nom 
536       """
537       nom = self.JDCName
538       self.JDCDisplay_courant.jdc.nom = nom
539       nom_page = self.nb.getcurselection()
540       num_page = self.nb.index(nom_page)
541       tab = self.nb.tab(num_page)
542       tab.configure(text = nom)
543
544    def exitEFICAS(self,event=None):
545       """
546           Permet de sortir d'EFICAS en demandant à l'utilisateur
547           s'il veut sauvegarder les modifications en cours
548       """
549       liste = self.GetListeJDCaSauvegarder()
550       if liste != [] :
551           # Certains fichiers n'ont pas été sauvegardés ...
552           if askyesno("Enregistrer modifications","Enregistrer les modifications ?") :
553               test = self.saveall(liste)
554               if test != 1 :
555                   return
556       if askyesno ("Quitter","Voulez-vous vraiment quitter l'application ?") :
557           for JDCDisplay in self.liste_JDCDisplay:
558               JDCDisplay.jdc.supprime()
559           self.appli.quit()
560           return
561
562    def GetListeJDCaSauvegarder(self) :
563       """ Retourne parmi la liste de tous les JDC ouverts la liste de ceux qui ont été modifiés """
564       if not self.JDCDisplay_courant : return []
565       if len(self.liste_JDCDisplay) == 0 : return l
566       l = []
567       for JDCDisplay in self.liste_JDCDisplay:
568           if JDCDisplay.modified == 'o' :
569               l.append(JDCDisplay)
570       return l
571
572    def copy(self,event=None):
573       """
574           Lance la copie sur le JDC courant
575       """
576       if self.JDCDisplay_courant : self.JDCDisplay_courant.doCopy()
577
578    def paste(self,event=None):
579       """
580            Lance le collage sur le JDC courant
581       """
582       if self.JDCDisplay_courant : self.JDCDisplay_courant.doPaste()
583
584    def cut(self,event=None):
585       """
586          Lance le cut sur le JDC courant
587       """
588       if self.JDCDisplay_courant: self.JDCDisplay_courant.doCut()
589
590    def delete(self):
591       """
592           Lance la suppression du noeud courant
593       """
594       if not self.JDCDisplay_courant : return
595       self.JDCDisplay_courant.init_modif()
596       self.JDCDisplay_courant.node_selected.delete()
597
598    def visuJDC_py(self,event=None):
599       """ 
600           Méthode permettant d'afficher dans une fenêtre à part l'écho au 
601             format python du jdc courant 
602       """
603       if not hasattr(self,'JDC') : return
604       jdc_fini = self.get_text_JDC('python')
605       if jdc_fini == None : return
606       Fenetre(self.appli,
607               titre = 'fichier '+ self.JDCName + ' à la syntaxe Python',
608               texte = jdc_fini)
609
610    def visuJDC(self):
611       """ 
612           Méthode permettant d'afficher dans une fenêtre à part l'écho au 
613             format .comm ou .py du jdc courant 
614       """
615       if not hasattr(self,'JDC') : return
616       titre = 'fichier '+ self.JDCName + ' à la syntaxe '+ self.code
617       format=self.appli.format_fichier.get()
618       self.jdc_fini = self.get_text_JDC(format)
619       if self.jdc_fini == None : return
620       self.visu_fichier_cmd = Fenetre(self.appli,titre=titre,texte = self.jdc_fini)
621
622    def get_text_JDC(self,format):
623       if generator.plugins.has_key(format):
624          # Le generateur existe on l'utilise
625          g=generator.plugins[format]()
626          jdc_formate=g.gener(self.JDC,format='beautifie')
627          if not g.cr.estvide():
628             self.appli.affiche_infos("Erreur à la generation")
629             showerror("Erreur à la generation","EFICAS ne sait pas convertir ce JDC")
630             return
631          else:
632             return jdc_formate
633       else:
634          # Il n'existe pas c'est une erreur
635          self.appli.affiche_infos("Format %s non reconnu" % format)
636          showerror("Format %s non reconnu" % format,"EFICAS ne sait pas convertir le JDC en format %s "% format)
637          return
638
639    def view_doc(self):
640       """
641           Permet d'ouvrir le fichier doc U de la commande au format pdf avec Acrobat Reader
642           - Ne fonctionne pas sous UNIX (chemin d'accès Acrobat Reader)
643           - indication du chemin d'accès aux fichiers pdf à revoir : trop statique
644       """
645       if not self.JDCDisplay_courant : return
646       try:
647           cle_doc = self.JDCDisplay_courant.node_selected.item.get_docu()
648           if cle_doc == None : return
649           cle_doc = string.replace(cle_doc,'.','')
650           cle_doc = string.replace(cle_doc,'-','')
651           commande = self.appli.CONFIGURATION.exec_acrobat
652           nom_fichier = cle_doc+".pdf"
653           fichier = os.path.abspath(os.path.join(self.appli.CONFIGURATION.path_doc,nom_fichier))
654           if os.name == 'nt':
655               os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
656           elif os.name == 'posix':
657               script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
658               pid = os.system(script)
659       except AttributeError:
660           traceback.print_exc()
661           pass
662
663    def visu_a_plat(self,event=None):
664       """ 
665           Méthode permettant d'afficher dans une fenêtre à part l'écho 'à plat' du jdc courant 
666       """
667       if not hasattr(self,'JDC') : return
668       titre = 'fichier '+ self.JDCName + ' à plat '
669       self.jdc_fini = self.get_text_JDC('aplat')
670       if self.jdc_fini == None : return
671       self.visu_fichier_cmd = Fenetre(self.appli,titre=titre,texte = self.jdc_fini)
672
673    def visu_txt_brut_JDC(self,event=None):
674       """
675            Méthode permettant d'afficher le jeu de commandes tel qu'il a été passé au JDC
676       """
677       if not hasattr(self,'JDC') : return
678       titre = "fichier de commandes utilisateur"
679       #texte = self.JDC.procedure
680       #if texte == None:
681       if self.JDCDisplay_courant.fichier == None:
682             self.appli.affiche_infos("Pas de fichier initial")
683             showerror("Impossible de visualiser le fichier initial",
684                       "EFICAS ne peut visualiser le fichier initial.\nIl s'agit d'un nouveau JDC")
685             return
686       f=open(self.JDCDisplay_courant.fichier,'r')
687       texte=f.read()
688       f.close()
689       self.visu_texte_JDC = Fenetre(self.appli,titre=titre,texte=texte)
690
691    def affichage_fichier_ini(self):
692       """
693            Affichage des valeurs des paramètres relus par Eficas
694       """
695       self.appli.CONFIGURATION.affichage_fichier_ini()
696
697    def saveall(self,liste):
698       """ 
699            Sauvegarde tous les JDC contenus dans liste 
700       """
701       test = 1
702       for JDCDisplay in liste :
703           self.JDCDisplay_courant=JDCDisplay
704           self.JDC = JDCDisplay.jdc
705           test = test * self.saveJDC(echo = 'non')
706       return test
707
708    def save_homard(self,nom,texte):
709        file_homard=nom+'.conf_homard'
710        try:
711            f=open(file_homard,'w')
712            for ligne in texte:
713                f.write(ligne)
714                f.write('\n')
715            f.close()
716        except:
717            print "Pb a la sauvegarde sous le format homard"
718        if self.appli.salome != 0:
719            import eficasEtude
720            self.appli.salome.rangeInStudy(file_homard,"_CONF")
721
722 # ---------------------------------------------------------------------------
723 #                       Méthodes liées aux mots-clés inconnus
724 # ---------------------------------------------------------------------------
725
726    def mc_inconnus(self):
727       l_mc = self.JDCDisplay_courant.jdc.get_liste_mc_inconnus()
728       o = fenetre_mc_inconnus(l_mc)
729       l = o.wait_new_list()
730       #print "mc_inconnus_new_list: ",l
731       #CCAR: Il n' y a pas de retour vers le JDC
732
733    def aideEFICAS(self,event=None):
734       AIDE.go(master=self.parent)
735
736    def update_jdc_courant(self):
737       self.JDCDisplay_courant.update()
738