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.
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.
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.
19 # ======================================================================
27 from centerwindow import centerwindow
29 class fenetre_mc_inconnus :
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
35 def __init__(self,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")
45 centerwindow(self.fenetre)
49 Initialise les structures de données
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
58 def init_frames(self):
60 Création des 2 frames devant contenir le label et la liste des MC inconnus
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)
71 Affichage du label dans la zone concernée
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()
78 wraplength = int(self.frame1.winfo_width()*0.8),
79 justify = 'center').place(relx=0.5,rely=0.5,anchor='center')
82 def init_liste_mc(self):
84 Affiche les mots-clés à modifier ou supprimer
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])
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)
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))
105 def init_boutons(self):
107 Construit les boutons Modifier,Supprimer et Fermer
108 Les deux premiers sont inactifs tant qu'aucun mot-clé n'est sélectionné
110 self.b_mod = Button(self.frame3,
112 disabledforeground = 'grey35',
114 command = self.modifie_mc)
115 self.b_sup = Button(self.frame3,
117 disabledforeground = 'grey35',
119 command = self.supprime_mc)
120 self.b_quit = Button(self.frame3,
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')
127 def wait_new_list(self):
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)
133 self.fenetre.wait_variable(self.var_quit)
134 self.fenetre.destroy()
137 def get_path(self,l_o):
139 Construit la chaîne de caractère contenant le chemin d'accès complet du mot-clé
143 txt = txt + o.nom+'/'
144 # on enlève le dernier slash en trop
148 def select_mc(self,mc,entry):
150 Enregistre le mot-clé passé en argument comme mot-clé courant
151 Active les boutons Modifier et Supprimer
153 self.desactive_entry()
155 self.entry_courante = entry
156 self.active_boutons()
159 def modifie_mc(self):
161 Modifie le nom du mot-clé en prenant la nouvelle valeur lue dans entry_courante
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]
169 self.desactive_boutons()
170 self.desactive_entry()
172 def supprime_mc(self):
174 Supprime le mot-clé courant de la liste
176 index = self.l_mc.index(self.mc_courant)
177 self.new_l_mc[index] = None
178 e,lab=self.widgets[index]
181 self.desactive_boutons()
182 self.desactive_entry()
184 def desactive_boutons(self):
186 Désactive les boutons Modifier et Supprimer
188 self.b_mod.configure(state='disabled')
189 self.b_sup.configure(state='disabled')
191 def active_boutons(self):
193 Active les boutons Modifier et Supprimer
195 self.b_mod.configure(state='normal')
196 self.b_sup.configure(state='normal')
198 def desactive_entry(self):
200 Désactive l'entry courante si elle existe
202 if self.entry_courante :
203 self.entry_courante.configure(state='disabled',relief='flat')
205 def active_entry(self):
207 Active l'entry courante si elle existe
209 if self.entry_courante :
210 self.entry_courante.configure(state='normal',relief='sunken')
214 Permet de fermer la fenêtre
218 if __name__ == '__main__':
219 fenetre_mc_inconnus(('toto','titi'))