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.geometry("400x400+0+0")
40 self.fenetre.title("Mots-clés inconnus dans le fichier de commandes")
46 centerwindow(self.fenetre)
50 Initialise les structures de données
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
59 def init_frames(self):
61 Création des 2 frames devant contenir le label et la liste des MC inconnus
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)
72 Affichage du label dans la zone concernée
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()
79 wraplength = int(self.frame1.winfo_width()*0.8),
80 justify = 'center').place(relx=0.5,rely=0.5,anchor='center')
83 def init_liste_mc(self):
85 Affiche les mots-clés à modifier ou supprimer
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])
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)
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))
106 def init_boutons(self):
108 Construit les boutons Modifier,Supprimer et Fermer
109 Les deux premiers sont inactifs tant qu'aucun mot-clé n'est sélectionné
111 self.b_mod = Button(self.frame3,
113 disabledforeground = 'grey35',
115 command = self.modifie_mc)
116 self.b_sup = Button(self.frame3,
118 disabledforeground = 'grey35',
120 command = self.supprime_mc)
121 self.b_quit = Button(self.frame3,
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')
129 def wait_new_list(self):
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)
135 self.fenetre.wait_variable(self.var_quit)
136 self.fenetre.destroy()
139 def get_path(self,l_o):
141 Construit la chaîne de caractère contenant le chemin d'accès complet du mot-clé
145 txt = txt + o.nom+'/'
146 # on enlève le dernier slash en trop
150 def select_mc(self,mc,entry):
152 Enregistre le mot-clé passé en argument comme mot-clé courant
153 Active les boutons Modifier et Supprimer
155 self.desactive_entry()
157 self.entry_courante = entry
158 self.active_boutons()
161 def modifie_mc(self):
163 Modifie le nom du mot-clé en prenant la nouvelle valeur lue dans entry_courante
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]
171 self.desactive_boutons()
172 self.desactive_entry()
174 def supprime_mc(self):
176 Supprime le mot-clé courant de la liste
178 index = self.l_mc.index(self.mc_courant)
179 self.new_l_mc[index] = None
180 e,lab=self.widgets[index]
183 self.desactive_boutons()
184 self.desactive_entry()
186 def desactive_boutons(self):
188 Désactive les boutons Modifier et Supprimer
190 self.b_mod.configure(state='disabled')
191 self.b_sup.configure(state='disabled')
193 def active_boutons(self):
195 Active les boutons Modifier et Supprimer
197 self.b_mod.configure(state='normal')
198 self.b_sup.configure(state='normal')
200 def desactive_entry(self):
202 Désactive l'entry courante si elle existe
204 if self.entry_courante :
205 self.entry_courante.configure(state='disabled',relief='flat')
207 def active_entry(self):
209 Active l'entry courante si elle existe
211 if self.entry_courante :
212 self.entry_courante.configure(state='normal',relief='sunken')
216 Permet de fermer la fenêtre
220 if __name__ == '__main__':
221 fenetre_mc_inconnus(('toto','titi'))