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.
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.
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.
20 # ======================================================================
28 from centerwindow import centerwindow
30 class fenetre_mc_inconnus :
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
36 def __init__(self,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")
47 centerwindow(self.fenetre)
48 self.fenetre.deiconify()
52 Initialise les structures de données
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
61 def init_frames(self):
63 Création des 2 frames devant contenir le label et la liste des MC inconnus
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)
74 Affichage du label dans la zone concernée
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()
81 wraplength = int(self.frame1.winfo_width()*0.8),
82 justify = 'center').place(relx=0.5,rely=0.5,anchor='center')
85 def init_liste_mc(self):
87 Affiche les mots-clés à modifier ou supprimer
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])
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)
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))
108 def init_boutons(self):
110 Construit les boutons Modifier,Supprimer et Fermer
111 Les deux premiers sont inactifs tant qu'aucun mot-clé n'est sélectionné
113 self.b_mod = Button(self.frame3,
115 disabledforeground = 'grey35',
117 command = self.modifie_mc)
118 self.b_sup = Button(self.frame3,
120 disabledforeground = 'grey35',
122 command = self.supprime_mc)
123 self.b_quit = Button(self.frame3,
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')
131 def wait_new_list(self):
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)
137 self.fenetre.wait_variable(self.var_quit)
138 self.fenetre.destroy()
141 def get_path(self,l_o):
143 Construit la chaîne de caractère contenant le chemin d'accès complet du mot-clé
147 txt = txt + o.nom+'/'
148 # on enlève le dernier slash en trop
152 def select_mc(self,mc,entry):
154 Enregistre le mot-clé passé en argument comme mot-clé courant
155 Active les boutons Modifier et Supprimer
157 self.desactive_entry()
159 self.entry_courante = entry
160 self.active_boutons()
163 def modifie_mc(self):
165 Modifie le nom du mot-clé en prenant la nouvelle valeur lue dans entry_courante
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]
173 self.desactive_boutons()
174 self.desactive_entry()
176 def supprime_mc(self):
178 Supprime le mot-clé courant de la liste
180 index = self.l_mc.index(self.mc_courant)
181 self.new_l_mc[index] = None
182 e,lab=self.widgets[index]
185 self.desactive_boutons()
186 self.desactive_entry()
188 def desactive_boutons(self):
190 Désactive les boutons Modifier et Supprimer
192 self.b_mod.configure(state='disabled')
193 self.b_sup.configure(state='disabled')
195 def active_boutons(self):
197 Active les boutons Modifier et Supprimer
199 self.b_mod.configure(state='normal')
200 self.b_sup.configure(state='normal')
202 def desactive_entry(self):
204 Désactive l'entry courante si elle existe
206 if self.entry_courante :
207 self.entry_courante.configure(state='disabled',relief='flat')
209 def active_entry(self):
211 Active l'entry courante si elle existe
213 if self.entry_courante :
214 self.entry_courante.configure(state='normal',relief='sunken')
218 Permet de fermer la fenêtre
222 if __name__ == '__main__':
223 fenetre_mc_inconnus(('toto','titi'))