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