Merge branch 'ihm-tkinter' into 'master'
Création d'une IHM avec tkinter Closes #4 See merge request sdjgeek/purge-registres-deces-insee!3
This commit is contained in:
commit
b438d3a7a5
|
@ -0,0 +1,126 @@
|
|||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
import tkinter.filedialog as tkfiledialog
|
||||
from multiprocessing import Process, Pipe
|
||||
|
||||
from trouver_decedes import trouver_decedes
|
||||
|
||||
class MainApplication(tk.Frame):
|
||||
def __init__(self, parent, *args, **kwargs):
|
||||
# Worker
|
||||
self.run = False
|
||||
self.pipe = None
|
||||
|
||||
# GUI
|
||||
tk.Frame.__init__(self, parent, *args, **kwargs)
|
||||
self.parent = parent
|
||||
self.frame = tk.Frame(parent)
|
||||
self.frame.pack()
|
||||
|
||||
# Sélection base INSEE
|
||||
self.label_bdd_insee = tk.Label(self.frame, text="Fichier de l'INSEE")
|
||||
self.label_bdd_insee.grid(row=0, column=0, sticky='e')
|
||||
self.value_bdd_insee = tk.StringVar()
|
||||
self.entry_bdd_insee = tk.Entry(self.frame, state='disabled', textvariable=self.value_bdd_insee)
|
||||
self.entry_bdd_insee.grid(row=0, column=1, sticky='ew')
|
||||
self.button_bdd_insee = tk.Button(self.frame, text="...", command=self.command_button_bdd_insee)
|
||||
self.button_bdd_insee.grid(row=0, column=2, sticky='w')
|
||||
|
||||
# Sélection répertoire sortie
|
||||
self.label_dir_out = tk.Label(self.frame, text="Répertoire de sortie")
|
||||
self.label_dir_out.grid(row=1, column=0, sticky='e')
|
||||
self.value_dir_out = tk.StringVar()
|
||||
self.entry_dir_out = tk.Entry(self.frame, state='disabled', textvariable=self.value_dir_out)
|
||||
self.entry_dir_out.grid(row=1, column=1, sticky='ew')
|
||||
self.button_dir_out = tk.Button(self.frame, text="...", command=self.command_button_dir_out)
|
||||
self.button_dir_out.grid(row=1, column=2, sticky='w')
|
||||
|
||||
# Sélection des unités à traiter
|
||||
self.label_units = tk.Label(self.frame, text="Unités à purger")
|
||||
self.label_units.grid(row=2, column=0, sticky='e')
|
||||
self.value_units = tk.StringVar()
|
||||
self.entry_units = tk.Entry(self.frame, textvariable=self.value_units)
|
||||
self.entry_units.grid(row=2, column=1, sticky='ew', columnspan="2")
|
||||
|
||||
# Bouton validation
|
||||
self.button_valid = tk.Button(self.frame, text="Ok", command=self.command_button_valid)
|
||||
self.button_valid.grid(row=3, column=0, columnspan=3)
|
||||
|
||||
# Barre de progression
|
||||
self.progressbar = ttk.Progressbar(self.frame, orient=tk.HORIZONTAL, mode='determinate')
|
||||
self.progressbar.grid(row=4, column=0, columnspan=3, sticky='ew')
|
||||
|
||||
# Affichage des logs
|
||||
self.text_log = tk.Text(self.frame, state='disabled')
|
||||
self.text_log.grid(row=0, column=3, rowspan=5, sticky='nesw')
|
||||
|
||||
def command_button_bdd_insee(self):
|
||||
self.value_bdd_insee.set(tkfiledialog.askopenfilename(title="Fichier de l'INSEE"))
|
||||
|
||||
def command_button_dir_out(self):
|
||||
self.value_dir_out.set(tkfiledialog.askdirectory(title="Répertoire de sortie"))
|
||||
|
||||
def add_log(self, text):
|
||||
self.text_log.configure(state='normal')
|
||||
self.text_log.insert(tk.END, text)
|
||||
self.text_log.configure(state='disabled')
|
||||
|
||||
def watch(self):
|
||||
if self.run:
|
||||
if self.pipe.poll():
|
||||
message = self.pipe.recv()
|
||||
if message.get('step', False):
|
||||
self.progressbar.step(message['step'])
|
||||
elif message.get('text', False):
|
||||
print(message['text'])
|
||||
self.add_log(message['text'])
|
||||
elif message.get('running', False):
|
||||
self.run = message['running']
|
||||
elif message.get('set_max', False):
|
||||
self.progressbar['maximum'] = message['set_max']
|
||||
self.parent.after(100, self.watch)
|
||||
else:
|
||||
print("Recherche terminée")
|
||||
self.add_log("\nRecherche terminée\n")
|
||||
self.button_valid.configure(state='normal')
|
||||
|
||||
def command_button_valid(self):
|
||||
self.button_valid.configure(state='disabled')
|
||||
self.run = True
|
||||
(conn1, conn2) = Pipe()
|
||||
self.pipe = conn1
|
||||
Worker(conn2, self.value_bdd_insee.get(), self.value_dir_out.get(), self.value_units.get().split(',')).start()
|
||||
self.watch()
|
||||
|
||||
|
||||
class Worker(Process):
|
||||
def __init__(self, pipe, bdd_insee, dir_out, units):
|
||||
Process.__init__(self)
|
||||
self.pipe = pipe
|
||||
self.bdd_insee = bdd_insee
|
||||
self.dir_out = dir_out
|
||||
self.units = units
|
||||
|
||||
def tracker(self, step=None, text=None, set_max=None, running=None):
|
||||
if step:
|
||||
self.pipe.send({'step': step})
|
||||
elif text:
|
||||
self.pipe.send({'text': text})
|
||||
elif set_max:
|
||||
self.pipe.send({'set_max': set_max})
|
||||
elif done:
|
||||
self.pipe.send({'running': running})
|
||||
|
||||
def run(self):
|
||||
trouver_decedes(chemin_base_donnees=self.bdd_insee,
|
||||
chemin_repertoire_sortie=self.dir_out,
|
||||
numeros_unites=self.units,
|
||||
tracker=self.tracker)
|
||||
self.pipe.send({'running': False})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
root.title('Recherche des personnes décédées dans les registres')
|
||||
MainApplication(root).pack(side="top", fill="both", expand=True)
|
||||
root.mainloop()
|
|
@ -47,7 +47,12 @@ from bdd_insee import BddInsee
|
|||
from site_eglise import SiteEglise
|
||||
|
||||
|
||||
def trouver_decedes(chemin_base_donnees, numeros_unites, chemin_repertoire_sortie, cookie_path=None):
|
||||
def default_tracker(step=None, text=None, set_max=None):
|
||||
if text:
|
||||
print(text)
|
||||
|
||||
|
||||
def trouver_decedes(chemin_base_donnees, numeros_unites, chemin_repertoire_sortie, cookie_path=None, tracker=None):
|
||||
"""Recherche les personnes décédées dans les registres
|
||||
|
||||
:param chemin_base_donnees: chemin vers le fichier SQLite
|
||||
|
@ -56,11 +61,13 @@ def trouver_decedes(chemin_base_donnees, numeros_unites, chemin_repertoire_sorti
|
|||
:param cookie_path: chemin vers la base de donnée des cookies
|
||||
|
||||
"""
|
||||
if tracker is None:
|
||||
tracker = default_tracker
|
||||
base_insee = BddInsee(chemin_base_donnees)
|
||||
site_eglise = SiteEglise(cookie_path)
|
||||
# Boucler sur la liste des unités
|
||||
for unite in numeros_unites:
|
||||
print(f"Unité {unite}")
|
||||
tracker(text=f"Unité {unite}")
|
||||
# Récupérer la liste des membres
|
||||
members = site_eglise.get_member_list(unite)
|
||||
|
||||
|
@ -69,6 +76,7 @@ def trouver_decedes(chemin_base_donnees, numeros_unites, chemin_repertoire_sorti
|
|||
with open(output_file, 'w') as out_file:
|
||||
out_file.write("Les lieux dans le fichier de l'INSEE sont donnés en Code Officiel Géographique en vigueur au moment de la prise en compte du décès\n")
|
||||
# Boucler sur la liste des membres
|
||||
tracker(set_max=len(members))
|
||||
for member in members:
|
||||
# Lire les noms et date de naissance
|
||||
name_registre = member['nameListPreferredLocal']
|
||||
|
@ -110,8 +118,9 @@ Dans le fichier de l'INSEE on peut trouver {person.last_name}, {person.first_nam
|
|||
né{feminin} le {person.jour_naissance:0>2}/{person.mois_naissance:0>2}/{person.annee_naissance:0>4} à {person.code_lieu_naissance}
|
||||
décédé{feminin} le {person.jour_deces:0>2}/{person.mois_deces:0>2}/{person.annee_deces:0>4} à {person.code_lieu_deces}
|
||||
"""
|
||||
print(text)
|
||||
tracker(text=text)
|
||||
out_file.write(text)
|
||||
tracker(step=1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue