]> SALOME platform Git repositories - tools/eficas.git/blob - Editeur/bureau.py
Salome HOME
merge de la branche BR_dev_mars_06 (tag V1_10b5) dans la branche principale
[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 include 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       return J
172
173    def newJDC(self,event=None):
174       """
175           Initialise un nouveau JDC vierge
176       """
177       self.appli.statusbar.reset_affichage_infos()
178
179       CONTEXT.unset_current_step()
180       J=self.cata[0].JdC(procedure="",appli=self.appli,
181                          cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
182                          rep_mat=self.appli.CONFIGURATION.rep_mat,
183                          )
184       J.analyse()
185       self.JDCName=J.nom
186       self.fileName=None
187       self.ShowJDC(J,self.JDCName)
188       self.appli.toolbar.active_boutons()
189       return J
190
191    def ShowJDC(self,JDC,nom,label_onglet=None,JDCDISPLAY=JDCDISPLAY,enregistre="non"):
192       """
193           Lance l'affichage du JDC cad création du JDCDisplay
194           Rajoute le JDCDisplay à la liste des JDCDisplay si label_onglet == None cad si on crée
195           bien un nouveau JDCDisplay et non si on remplace (renommage de l'onglet)
196       """
197       self.JDC=JDC
198       self.JDCName = self.JDC.nom = nom
199       if label_onglet == None :
200           # On veut un nouvel onglet
201           label_onglet = self.GetLabelJDC()
202           self.nb.add(label_onglet,tab_text = nom,tab_width=20)
203           new = 'oui'
204       else :
205           new = 'non'
206       self.JDCDisplay_courant=JDCDISPLAY(self.JDC,nom,appli=self.appli,parent=self.nb.page(label_onglet))
207       if new == 'oui':
208           self.liste_JDCDisplay.append(self.JDCDisplay_courant)
209       self.JDCDisplay_courant.modified='n'
210       if enregistre != "non" :
211          self.JDCDisplay_courant.fichier=self.fileName
212       else :
213          self.initialdir = self.appli.CONFIGURATION.rep_user
214       self.nb.selectpage(label_onglet)
215       self.nb.setnaturalsize()
216       self.nb.bind_all("<Key-Next>",lambda e,s=self:s.selectArbreDown())
217       self.nb.bind_all("<Key-Prior>",lambda e,s=self:s.selectArbreUp())
218       self.nb.bind_all("<Insert>",lambda e,s=self:s.deplieReplieNode())
219       texte = "Jeu de commandes :" + self.JDCName+" ouvert"
220       CONNECTOR.Connect(JDC,"close",self.onClose,(self.JDCDisplay_courant,))
221       self.appli.affiche_infos(texte)
222
223    def onClose(self,jdcdisplay):
224       #print "onClose",jdcdisplay
225       self.closeJDCDISPLAY(jdcdisplay)
226
227    def closeJDCDISPLAY(self,jdc):
228       """
229         Ferme le jdcdisplay spécifié par l'argument jdc
230       """
231       if jdc is self.JDCDisplay_courant:
232          # on ferme le jdcdisplay courant
233          self.closeSelectedJDC()
234       else:
235          # on ferme un autre jdcdisplay que le courant
236          old_JDCDisplay=self.JDCDisplay_courant
237          old_page=self.nb.getcurselection()
238
239          self.JDCDisplay_courant=jdc
240          self.JDC=jdc.jdc
241          numero_jdc=self.liste_JDCDisplay.index(jdc)
242          self.nb.selectpage(numero_jdc)
243          #print numero_jdc
244       
245          self.closeSelectedJDC()
246          self.JDCDisplay_courant=old_JDCDisplay
247          self.JDC=old_JDCDisplay.jdc
248          self.nb.selectpage(old_page)
249
250    def closeJDC (self,event=None) :
251       """
252           Ferme le JDC associé au JDCDISPLAY selectionné
253       """
254       if self.JDCDisplay_courant :
255          self.JDCDisplay_courant.jdc.close()
256
257    def closeSelectedJDC (self) :
258       """
259       Ferme le JDC courant et détruit l'onglet associé dans le notebook self.nb
260       """
261       if self.JDCDisplay_courant.modified == 'o' :
262           message = "Voulez-vous sauvegarder le jeu de commandes "+self.JDC.nom+" courant ?"
263           reponse = askyesno(title="Sauvegarde du jdc courant",
264                              message=message)
265           if reponse :
266               test = self.saveJDC()
267               if test == 0 :
268                   self.appli.affiche_infos("Sauvegarde impossible")
269                   return
270
271       CONNECTOR.Disconnect(self.JDCDisplay_courant.jdc,"close",self.onClose,(self.JDCDisplay_courant,))
272       self.JDCDisplay_courant.supprime()
273       self.JDCDisplay_courant.jdc.supprime()
274       self.liste_JDCDisplay.remove(self.JDCDisplay_courant)
275       # Active le mecanisme de selection du notebook (selectJDC)
276       self.nb.delete(self.nb.getcurselection())
277
278       try:
279           index = self.nb.index(self.nb.getcurselection())
280           self.JDCDisplay_courant = self.liste_JDCDisplay[index]
281           self.JDC = self.JDCDisplay_courant.jdc
282       except:
283           self.JDC = None
284           self.JDCDisplay_courant = None
285           self.appli.toolbar.inactive_boutons()
286
287    def visuCRJDC(self,event=None):
288       return self.visuCR(mode='JDC')
289
290    def visuCR(self,mode):
291       """
292       Méthode permettant l'affichage du rapport de validation
293       """
294       if mode == 'JDC':
295           if not hasattr(self,'JDC') : return
296           titre="rapport de validation du jeu de commandes courant"
297           cr = self.JDC.report()
298           #self.update_jdc_courant()
299       elif mode == 'CATA':
300           from Noyau.N_CR import CR
301           cr = CR()
302           cr.debut = "Début rapport de validation du catalogue"
303           cr.fin = "Fin rapport de validation du catalogue"
304           titre="rapport de validation du catalogue"
305           if hasattr(self,'cata_ordonne_cr') :
306               cr.add(self.cata_ordonne_cr)
307           if hasattr(self,'cata_dev_ordonne_cr') :
308               cr.add(self.cata_dev_ordonne_cr)
309           for cata in self.cata:
310               if hasattr(cata,'JdC'):
311                   cr.add(cata.JdC.report())
312       texte_cr = str(cr)
313       self.visu_texte_cr = Fenetre(self.appli,titre=titre,texte=texte_cr)
314
315    def openJDC(self,event=None,file=None,units=None,enregistre="oui"):
316       """
317           Demande à l'utilisateur quel JDC existant il veut ouvrir
318       """
319       if self.code == 'ASTER':
320           filetypes = ( ("format "+self.appli.format_fichier.get(), ".com*"),("Tous",'*'))
321       elif self.code == 'HOMARD' :
322           filetypes = ( ("format "+self.appli.format_fichier.get(), ".py"),("Tous",'*'))
323       else:
324           filetypes = ( ("format "+self.appli.format_fichier.get(), ".py"),)
325       if not hasattr(self,'initialdir'):
326          self.initialdir = self.appli.CONFIGURATION.initialdir
327
328       if not file :
329           file = askopenfilename(title="Ouverture d'un fichier de commandes Aster",
330                                  defaultextension=".comm",
331                                  filetypes = filetypes,
332                                  initialdir = self.initialdir)
333       if file :
334           self.fileName = file
335           e=extension_fichier(file)
336           self.JDCName=stripPath(file)
337           self.initialdir = os.path.dirname(os.path.abspath(file))
338       else :
339           return
340
341       format=self.appli.format_fichier.get()
342       # Il faut convertir le contenu du fichier en fonction du format
343       if convert.plugins.has_key(format):
344          # Le convertisseur existe on l'utilise
345          p=convert.plugins[format]()
346          p.readfile(file)
347          text=p.convert('exec',self.appli)
348          if not p.cr.estvide(): 
349             self.appli.affiche_infos("Erreur à la conversion")
350             Fenetre(self.appli,
351                     titre="compte-rendu d'erreurs, EFICAS ne sait pas convertir ce fichier",
352                     texte = str(p.cr)).wait()
353             return
354          if enregistre == "oui" :
355             self.appli.listeFichiers.aOuvert(file)
356       else:
357          # Il n'existe pas c'est une erreur
358          self.appli.affiche_infos("Type de fichier non reconnu")
359          showerror("Type de fichier non reconnu","EFICAS ne sait pas ouvrir ce type de fichier")
360          return
361
362       # On se met dans le repertoire ou se trouve le fichier de commandes
363       # pour trouver les eventuels fichiers include ou autres
364       # localises a cote du fichier de commandes
365       os.chdir(self.initialdir)
366       CONTEXT.unset_current_step()
367       J=self.cata[0].JdC(procedure=text,appli=self.appli,
368                          cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
369                          nom = self.JDCName,
370                          rep_mat=self.appli.CONFIGURATION.rep_mat,
371                          )
372       if units is not None:
373          J.recorded_units=units
374          J.old_recorded_units=units
375
376       J.analyse()
377       txt_exception = J.cr.get_mess_exception()
378       if txt_exception :
379           # des exceptions ont été levées à la création du JDC 
380           # --> on affiche les erreurs mais pas le JDC
381           self.JDC=J
382           self.appli.affiche_infos("Erreur fatale au chargement de %s" %file)
383           if self.appli.test == 0 :
384              showerror("Erreur fatale au chargement d'un fichier",txt_exception)
385       else:
386           self.ShowJDC(J,self.JDCName,enregistre=enregistre)
387           self.appli.toolbar.active_boutons()
388           # si le JDC ne contient rien (vide), on retourne ici
389           if len(self.JDC.etapes) == 0 : return
390           # dans le cas où le JDC est invalide, on affiche son CR
391           if not self.JDC.isvalid():
392              self.appli.top.update()
393              self.visuCR(mode='JDC')
394       return J
395
396    def deplieReplieNode(self):
397        self.JDCDisplay_courant.tree.tree.deplieReplieNode()
398
399    def selectArbreDown(self):
400        self.JDCDisplay_courant.tree.tree.canvas.focus_set()
401        self.JDCDisplay_courant.tree.tree.mot_down_force()
402
403    def selectArbreUp(self):
404        self.JDCDisplay_courant.tree.tree.canvas.focus_set()
405        self.JDCDisplay_courant.tree.tree.mot_up_force()
406
407    def GetLabelJDC(self,nb_jdc = 'absent'):
408       """
409       Retourne le label de l'onglet du NoteBook associé au JDC à afficher
410       """
411       if nb_jdc == 'absent':
412           nb_jdc = len(self.nb.pagenames())
413       nb_jdc = nb_jdc+1
414       label_onglet = 'JDC'+`nb_jdc`
415       if label_onglet not in self.nb.pagenames() :
416           return label_onglet
417       else :
418           return self.GetLabelJDC(nb_jdc)
419
420    def saveasJDC(self,event=None):
421       """ 
422            Sauvegarde le JDC courant en demandant impérativement à l'utilisateur de
423            donner le nom du fichier de sauvegarde 
424       """
425       self.saveJDC(echo='oui')
426
427    def saveJDC(self,echo='non'):
428       """ 
429           Sauvegarde le JDC courant.
430           Retourne 1 si la sauvegarde s'est bien faite, 0 sinon.
431           Si echo = 'oui' : interactif (l'utilisateur donne le nom sous lequel il 
432                             veut sauver le JDC
433           Si echo = 'non' : muet (sauvegarde le JDC dans JDC.procedure)
434       """
435       ok = 0
436       if not hasattr(self,'JDC') : return 0
437       format=self.appli.format_fichier.get()
438       if generator.plugins.has_key(format):
439          # Le generateur existe on l'utilise
440          g=generator.plugins[format]()
441          jdc_formate=g.gener(self.JDC,format='beautifie')
442          if format == 'homard':
443             self.jdc_homard=g.get_homard()
444          if not g.cr.estvide():
445             self.appli.affiche_infos("Erreur à la generation")
446             showerror("Erreur à la generation","EFICAS ne sait pas convertir ce JDC")
447             return
448       else:
449          # Il n'existe pas c'est une erreur
450          self.appli.affiche_infos("Format %s non reconnu" % format)
451          showerror("Format %s non reconnu" % format,"EFICAS ne sait pas convertir le JDC")
452          return
453       self.jdc_fini = string.replace(jdc_formate,'\r\n','\n')
454
455       if echo =='oui' or self.JDCDisplay_courant.fichier == None:
456          ok = self.asknomsauvegardeJDC()
457       elif self.JDCDisplay_courant.fichier != None :
458          # le JDC a déjà un nom : on sauvegarde directement sans demander
459          # un autre nom au développeur
460          if not save_in_file(self.JDCDisplay_courant.fichier,self.jdc_fini,self.appli.dir) :
461               showinfo("Erreur","Problème à la sauvegarde du fichier :" + `self.JDCDisplay_courant.fichier`)
462               #return 0
463               ok = 0
464          else :
465               if self.appli.format_fichier.get() == 'homard':
466                   self.save_homard(self.JDCDisplay_courant.fichier,self.jdc_homard)
467               self.JDCDisplay_courant.stop_modif()
468               self.appli.affiche_infos("sauvegarde de "+`self.JDCDisplay_courant.fichier`+" effectuée")
469               ok = 1
470
471       if ok and hasattr( self.appli, 'salome'):
472          # eficas a été lancé à partir deSalome
473          #1)ajout dans l'arbre d'étude du nom du jdc
474          ok, msg = self.appli.addJdcInSalome( self.JDCDisplay_courant.fichier )
475
476          #2)CS_pbruno ??
477          from panelsSalome import SALOME_UNIQUE_BASE_Panel
478          if len(SALOME_UNIQUE_BASE_Panel.dict_fichier_unite) > 0 :
479             print 'CS_pbruno if len(SALOMchier_unite) > 0 :???????'
480             self.appli.creeConfigTxt( self.appli.CONFIGURATION.initialdir, SALOME_UNIQUE_BASE_Panel.dict_fichier_unite )
481
482          #3)création/mise à jours d'un maillage dans Salome
483          self.appli.createOrUpdateMesh()
484       return ok
485
486    def asknomsauvegardeJDC(self):
487       """ Demande à l'utilsateur le nom sous lequel il veut sauvegarder le JDC courant """
488       titre = "Sauvegarde d'un fichier de commandes "+self.code
489       if self.code == 'ASTER':
490           defext = ".comm"
491           filtyp = ( ("ASTER", ".comm"),)
492       else :
493           defext = ".py"
494           filtyp = ( (self.code, ".py"),)
495       sauvegarde = asksaveasfilename(title=titre,
496                                      defaultextension=defext,
497                                      filetypes = filtyp,
498                                      initialdir = self.initialdir)
499                             #initialdir = self.appli.CONFIGURATION.initialdir)
500                             #initialdir = self.appli.CONFIGURATION.rep_user)
501       if sauvegarde :
502           if not save_in_file(sauvegarde,self.jdc_fini,None) :
503               showinfo("Erreur","Problème à la sauvegarde du fichier "+`sauvegarde`)
504               return 0
505           else :
506               if self.appli.format_fichier.get() == 'homard':
507                   self.save_homard(sauvegarde,self.jdc_homard)
508               self.JDCDisplay_courant.stop_modif()
509               self.appli.affiche_infos("Sauvegarde effectuée")
510               if sauvegarde != self.JDCDisplay_courant.fichier :
511                   # l'utilisateur a sauvegardé le JDC sous un autre nom
512                   self.JDCDisplay_courant.fichier = sauvegarde
513                   self.JDCName = self.JDC.nom = stripPath(sauvegarde)
514                   self.JDC.changefichier(sauvegarde)
515                   self.changeNomPage()
516               return 1
517       else :
518           return 0
519
520    def changeNomPage(self):
521       """ Change le nom de l'onglet contenant le JDC courant : en fait détruit l'actuel
522           et recrée un autre onglet à la même place avec le bon nom 
523       """
524       nom = self.JDCName
525       self.JDCDisplay_courant.jdc.nom = nom
526       nom_page = self.nb.getcurselection()
527       num_page = self.nb.index(nom_page)
528       tab = self.nb.tab(num_page)
529       tab.configure(text = nom)
530
531    def exitEFICAS(self,event=None):
532       """
533           Permet de sortir d'EFICAS en demandant à l'utilisateur
534           s'il veut sauvegarder les modifications en cours
535       """
536       liste = self.GetListeJDCaSauvegarder()
537       if liste != [] :
538           # Certains fichiers n'ont pas été sauvegardés ...
539           if askyesno("Enregistrer modifications","Enregistrer les modifications ?") :
540               test = self.saveall(liste)
541               if test != 1 :
542                   return
543       if askyesno ("Quitter","Voulez-vous vraiment quitter l'application ?") :
544           for JDCDisplay in self.liste_JDCDisplay:
545               JDCDisplay.jdc.supprime()
546           self.appli.quit()
547           return
548
549    def GetListeJDCaSauvegarder(self) :
550       """ Retourne parmi la liste de tous les JDC ouverts la liste de ceux qui ont été modifiés """
551       if not self.JDCDisplay_courant : return []
552       if len(self.liste_JDCDisplay) == 0 : return l
553       l = []
554       for JDCDisplay in self.liste_JDCDisplay:
555           if JDCDisplay.modified == 'o' :
556               l.append(JDCDisplay)
557       return l
558
559    def copy(self,event=None):
560       """
561           Lance la copie sur le JDC courant
562       """
563       if self.JDCDisplay_courant : self.JDCDisplay_courant.doCopy()
564
565    def paste(self,event=None):
566       """
567            Lance le collage sur le JDC courant
568       """
569       if self.JDCDisplay_courant : self.JDCDisplay_courant.doPaste()
570
571    def cut(self,event=None):
572       """
573          Lance le cut sur le JDC courant
574       """
575       if self.JDCDisplay_courant: self.JDCDisplay_courant.doCut()
576
577    def delete(self):
578       """
579           Lance la suppression du noeud courant
580       """
581       if not self.JDCDisplay_courant : return
582       self.JDCDisplay_courant.init_modif()
583       self.JDCDisplay_courant.node_selected.delete()
584
585    def visuJDC_py(self,event=None):
586       """ 
587           Méthode permettant d'afficher dans une fenêtre à part l'écho au 
588             format python du jdc courant 
589       """
590       if not hasattr(self,'JDC') : return
591       jdc_fini = self.get_text_JDC('python')
592       if jdc_fini == None : return
593       Fenetre(self.appli,
594               titre = 'fichier '+ self.JDCName + ' à la syntaxe Python',
595               texte = jdc_fini)
596
597    def visuJDC(self):
598       """ 
599           Méthode permettant d'afficher dans une fenêtre à part l'écho au 
600             format .comm ou .py du jdc courant 
601       """
602       if not hasattr(self,'JDC') : return
603       titre = 'fichier '+ self.JDCName + ' à la syntaxe '+ self.code
604       format=self.appli.format_fichier.get()
605       self.jdc_fini = self.get_text_JDC(format)
606       if self.jdc_fini == None : return
607       self.visu_fichier_cmd = Fenetre(self.appli,titre=titre,texte = self.jdc_fini)
608
609    def get_text_JDC(self,format):
610       if generator.plugins.has_key(format):
611          # Le generateur existe on l'utilise
612          g=generator.plugins[format]()
613          jdc_formate=g.gener(self.JDC,format='beautifie')
614          if not g.cr.estvide():
615             self.appli.affiche_infos("Erreur à la generation")
616             showerror("Erreur à la generation","EFICAS ne sait pas convertir ce JDC")
617             return
618          else:
619             return jdc_formate
620       else:
621          # Il n'existe pas c'est une erreur
622          self.appli.affiche_infos("Format %s non reconnu" % format)
623          showerror("Format %s non reconnu" % format,"EFICAS ne sait pas convertir le JDC en format %s "% format)
624          return
625
626    def view_doc(self):
627       """
628           Permet d'ouvrir le fichier doc U de la commande au format pdf avec Acrobat Reader
629           - Ne fonctionne pas sous UNIX (chemin d'accès Acrobat Reader)
630           - indication du chemin d'accès aux fichiers pdf à revoir : trop statique
631       """
632       if not self.JDCDisplay_courant : return
633       try:
634           cle_doc = self.JDCDisplay_courant.node_selected.item.get_docu()
635           if cle_doc == None : return
636           cle_doc = string.replace(cle_doc,'.','')
637           cle_doc = string.replace(cle_doc,'-','')
638           commande = self.appli.CONFIGURATION.exec_acrobat
639           nom_fichier = cle_doc+".pdf"
640           fichier = os.path.abspath(os.path.join(self.appli.CONFIGURATION.path_doc,nom_fichier))
641           if os.name == 'nt':
642               os.spawnv(os.P_NOWAIT,commande,(commande,fichier,))
643           elif os.name == 'posix':
644               script ="#!/usr/bin/sh \n%s %s&" %(commande,fichier)
645               pid = os.system(script)
646       except AttributeError:
647           traceback.print_exc()
648           pass
649
650    def visu_a_plat(self,event=None):
651       """ 
652           Méthode permettant d'afficher dans une fenêtre à part l'écho 'à plat' du jdc courant 
653       """
654       if not hasattr(self,'JDC') : return
655       titre = 'fichier '+ self.JDCName + ' à plat '
656       self.jdc_fini = self.get_text_JDC('aplat')
657       if self.jdc_fini == None : return
658       self.visu_fichier_cmd = Fenetre(self.appli,titre=titre,texte = self.jdc_fini)
659
660    def visu_txt_brut_JDC(self,event=None):
661       """
662            Méthode permettant d'afficher le jeu de commandes tel qu'il a été passé au JDC
663       """
664       if not hasattr(self,'JDC') : return
665       titre = "fichier de commandes utilisateur"
666       #texte = self.JDC.procedure
667       #if texte == None:
668       if self.JDCDisplay_courant.fichier == None:
669             self.appli.affiche_infos("Pas de fichier initial")
670             showerror("Impossible de visualiser le fichier initial",
671                       "EFICAS ne peut visualiser le fichier initial.\nIl s'agit d'un nouveau JDC")
672             return
673       os.chdir(self.appli.dir)
674       f=open(self.JDCDisplay_courant.fichier,'r')
675       texte=f.read()
676       f.close()
677       self.visu_texte_JDC = Fenetre(self.appli,titre=titre,texte=texte)
678
679    def affichage_fichier_ini(self):
680       """
681            Affichage des valeurs des paramètres relus par Eficas
682       """
683       self.appli.CONFIGURATION.affichage_fichier_ini()
684
685    def saveall(self,liste):
686       """ 
687            Sauvegarde tous les JDC contenus dans liste 
688       """
689       test = 1
690       for JDCDisplay in liste :
691           self.JDCDisplay_courant=JDCDisplay
692           self.JDC = JDCDisplay.jdc
693           test = test * self.saveJDC(echo = 'non')
694       return test
695
696    def save_homard(self,nom,texte):
697        file_homard=nom+'.conf_homard'
698        try:
699            f=open(file_homard,'w')
700            for ligne in texte:
701                f.write(ligne)
702                f.write('\n')
703            f.close()
704        except:
705            print "Pb a la sauvegarde sous le format homard"
706        if hasattr( self.appli, 'salome'):
707            import eficasEtude
708            self.appli.salome.rangeInStudy(file_homard,"_CONF")
709
710 # ---------------------------------------------------------------------------
711 #                             Méthodes liées aux mots-clés inconnus
712 # ---------------------------------------------------------------------------
713
714    def mc_inconnus(self):
715       l_mc = self.JDCDisplay_courant.jdc.get_liste_mc_inconnus()
716       o = fenetre_mc_inconnus(l_mc)
717       l = o.wait_new_list()
718       #print "mc_inconnus_new_list: ",l
719       #CCAR: Il n' y a pas de retour vers le JDC
720
721    def aideEFICAS(self,event=None):
722       AIDE.go(master=self.parent)
723
724    def update_jdc_courant(self):
725       self.JDCDisplay_courant.update()
726