]> SALOME platform Git repositories - tools/eficas.git/blob - Editeur/fenetre_mc_inconnus.py
Salome HOME
CCAR:amelioration de la fonctionnalité mots clés inconnus
[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                             
127     def wait_new_list(self):
128         """
129         Cette méthode rend cette toplevel bloquante.
130         Dès que la variable var_quit est modifiée, on continue l'exécution de cette
131         méthode (et on quitte)
132         """
133         self.fenetre.wait_variable(self.var_quit)
134         self.fenetre.destroy()
135         return self.new_l_mc
136                            
137     def get_path(self,l_o):
138         """
139         Construit la chaîne de caractère contenant le chemin d'accès complet du mot-clé
140         """
141         txt = ''
142         for o in l_o :
143            txt = txt + o.nom+'/'
144         # on enlève le dernier slash en trop
145         txt = txt[0:-1]
146         return txt    
147     
148     def select_mc(self,mc,entry):
149         """
150         Enregistre le mot-clé passé en argument comme mot-clé courant
151         Active les boutons Modifier et Supprimer
152         """
153         self.desactive_entry()
154         self.mc_courant     = mc
155         self.entry_courante = entry
156         self.active_boutons()
157         self.active_entry()
158
159     def modifie_mc(self):
160         """
161         Modifie le nom du mot-clé en prenant la nouvelle valeur lue dans entry_courante
162         """
163         new_nom_mc = self.entry_courante.get()
164         index = self.l_mc.index(self.mc_courant)
165         new_mc = self.new_l_mc[index]
166         new_mc[-2] = new_nom_mc
167         objet_pere = self.mc_courant[-3]
168         
169         self.desactive_boutons()
170         self.desactive_entry()
171
172     def supprime_mc(self):
173         """
174         Supprime le mot-clé courant de la liste
175         """
176         index = self.l_mc.index(self.mc_courant)
177         self.new_l_mc[index] = None
178         e,lab=self.widgets[index]
179         e.grid_remove()
180         lab.grid_remove()
181         self.desactive_boutons()
182         self.desactive_entry()  
183         
184     def desactive_boutons(self):
185         """
186         Désactive les boutons Modifier et Supprimer
187         """
188         self.b_mod.configure(state='disabled')
189         self.b_sup.configure(state='disabled')
190                 
191     def active_boutons(self):
192         """
193         Active les boutons Modifier et Supprimer
194         """
195         self.b_mod.configure(state='normal')
196         self.b_sup.configure(state='normal')
197
198     def desactive_entry(self):
199         """
200         Désactive l'entry courante si elle existe
201         """
202         if self.entry_courante :
203            self.entry_courante.configure(state='disabled',relief='flat')
204            
205     def active_entry(self):
206         """
207         Active l'entry courante si elle existe
208         """
209         if self.entry_courante :
210            self.entry_courante.configure(state='normal',relief='sunken')
211                    
212     def quit(self):
213         """
214         Permet de fermer la fenêtre
215         """
216         self.var_quit.set(1)
217
218 if __name__ == '__main__':
219    fenetre_mc_inconnus(('toto','titi'))