Salome HOME
correction pour acception de concept liste
[tools/eficas.git] / Editeur / fenetre_mc_inconnus.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 """
23 # Modules Python
24 from Tkinter import *
25 import copy
26
27 # Modules Eficas
28 from centerwindow import centerwindow
29
30 class fenetre_mc_inconnus :
31     """
32        Cette classe sert à construire la fenêtre qui apparaît dans EFICAS 
33        lorsque des mots-clés inconnus ont été trouvés dans le fichier de 
34        commandes que l'on est en train de lire
35     """
36     def __init__(self,l_mc):
37        self.l_mc = l_mc
38        self.fenetre = Toplevel()
39        self.fenetre.withdraw()
40        self.fenetre.geometry("400x400+0+0")
41        self.fenetre.title("Mots-clés inconnus dans le fichier de commandes")
42        self.init()
43        self.init_frames()
44        self.init_label()
45        self.init_liste_mc()
46        self.init_boutons()
47        centerwindow(self.fenetre)
48        self.fenetre.deiconify()
49
50     def init(self) :
51        """
52        Initialise les structures de données
53        """
54        self.new_l_mc = []
55        for mc in self.l_mc :
56            self.new_l_mc.append(copy.copy(mc))
57        self.mc_courant = None
58        self.var_quit = IntVar(0)
59        self.entry_courante = None
60                
61     def init_frames(self):
62        """
63        Création des 2 frames devant contenir le label et la liste des MC inconnus 
64        """
65        self.frame1 = Frame(self.fenetre)
66        self.frame2 = Frame(self.fenetre)
67        self.frame3 = Frame(self.fenetre)
68        self.frame1.place(relx=0,rely=0,relheight=0.2,relwidth=1)
69        self.frame2.place(relx=0,rely=0.2,relheight=0.6,relwidth=1)
70        self.frame3.place(relx=0,rely=0.8,relheight=0.2,relwidth=1)
71     
72     def init_label(self):
73        """
74        Affichage du label dans la zone concernée
75        """
76        txt = " Un ou plusieurs mots-clés inconnus ont été trouvés dans le fichier de commandes."
77        #txt = txt + "En cliquant sur leur nom, vous pourrez soit corriger l'orthographe soit supprimer ce mot-clé"
78        self.fenetre.update_idletasks()
79        Label(self.frame1,
80              text = txt,
81              wraplength = int(self.frame1.winfo_width()*0.8),
82              justify = 'center').place(relx=0.5,rely=0.5,anchor='center')   
83     
84     
85     def init_liste_mc(self):
86        """
87        Affiche les mots-clés à modifier ou supprimer  
88        """
89        i=0
90        self.widgets=[]
91        for mc in self.l_mc :
92            # mc est une liste :
93            # mc contient comme premiers arguments l'étape et éventuellement les blocs, mcfact ...
94            # et contient comme 2 derniers éléments le nom du mot-clé et sa valeur
95            path_mc = self.get_path(mc[0:-2])
96            nom_mc  = mc[-2]
97            lab=Label(self.frame2,text = path_mc)
98            lab.grid(row=i,column=1,sticky=W)
99            e = Entry(self.frame2)
100            e.grid(row=i,column=0,sticky=W)
101            e.insert(END,nom_mc)
102            #e.bind("<Button-1>",lambda event,en=e,m=mc,s=self : s.select_mc(m,en))
103            #e.bind("<Return>",lambda e,s=self : s.modifie_mc())
104            e.configure(relief='flat',state='disabled')
105            self.widgets.append((e,lab))
106            i=i+1
107
108     def init_boutons(self):
109         """
110         Construit les boutons Modifier,Supprimer et Fermer 
111         Les deux premiers sont inactifs tant qu'aucun mot-clé n'est sélectionné
112         """
113         self.b_mod = Button(self.frame3,
114                             text = "Modifier",
115                             disabledforeground = 'grey35',
116                             state='disabled',
117                             command = self.modifie_mc)
118         self.b_sup = Button(self.frame3,
119                             text = "Supprimer",
120                             disabledforeground = 'grey35',
121                             state='disabled',
122                             command = self.supprime_mc)
123         self.b_quit = Button(self.frame3,
124                             text = "Fermer",
125                             command = self.quit)
126         #self.b_mod.place(relx=0.25,rely=0.5,anchor='center')
127         #self.b_sup.place(relx=0.50,rely=0.5,anchor='center')
128         #self.b_quit.place(relx=0.75,rely=0.5,anchor='center')
129         self.b_quit.place(relx=0.50,rely=0.5,anchor='center')
130                             
131     def wait_new_list(self):
132         """
133         Cette méthode rend cette toplevel bloquante.
134         Dès que la variable var_quit est modifiée, on continue l'exécution de cette
135         méthode (et on quitte)
136         """
137         self.fenetre.wait_variable(self.var_quit)
138         self.fenetre.destroy()
139         return self.new_l_mc
140                            
141     def get_path(self,l_o):
142         """
143         Construit la chaîne de caractère contenant le chemin d'accès complet du mot-clé
144         """
145         txt = ''
146         for o in l_o :
147            txt = txt + o.nom+'/'
148         # on enlève le dernier slash en trop
149         txt = txt[0:-1]
150         return txt    
151     
152     def select_mc(self,mc,entry):
153         """
154         Enregistre le mot-clé passé en argument comme mot-clé courant
155         Active les boutons Modifier et Supprimer
156         """
157         self.desactive_entry()
158         self.mc_courant     = mc
159         self.entry_courante = entry
160         self.active_boutons()
161         self.active_entry()
162
163     def modifie_mc(self):
164         """
165         Modifie le nom du mot-clé en prenant la nouvelle valeur lue dans entry_courante
166         """
167         new_nom_mc = self.entry_courante.get()
168         index = self.l_mc.index(self.mc_courant)
169         new_mc = self.new_l_mc[index]
170         new_mc[-2] = new_nom_mc
171         objet_pere = self.mc_courant[-3]
172         
173         self.desactive_boutons()
174         self.desactive_entry()
175
176     def supprime_mc(self):
177         """
178         Supprime le mot-clé courant de la liste
179         """
180         index = self.l_mc.index(self.mc_courant)
181         self.new_l_mc[index] = None
182         e,lab=self.widgets[index]
183         e.grid_remove()
184         lab.grid_remove()
185         self.desactive_boutons()
186         self.desactive_entry()  
187         
188     def desactive_boutons(self):
189         """
190         Désactive les boutons Modifier et Supprimer
191         """
192         self.b_mod.configure(state='disabled')
193         self.b_sup.configure(state='disabled')
194                 
195     def active_boutons(self):
196         """
197         Active les boutons Modifier et Supprimer
198         """
199         self.b_mod.configure(state='normal')
200         self.b_sup.configure(state='normal')
201
202     def desactive_entry(self):
203         """
204         Désactive l'entry courante si elle existe
205         """
206         if self.entry_courante :
207            self.entry_courante.configure(state='disabled',relief='flat')
208            
209     def active_entry(self):
210         """
211         Active l'entry courante si elle existe
212         """
213         if self.entry_courante :
214            self.entry_courante.configure(state='normal',relief='sunken')
215                    
216     def quit(self):
217         """
218         Permet de fermer la fenêtre
219         """
220         self.var_quit.set(1)
221
222 if __name__ == '__main__':
223    fenetre_mc_inconnus(('toto','titi'))