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