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