2020-07-17 21:49:45 +02:00
|
|
|
"""
|
|
|
|
Copyright (c) 2020 Sdj Geek
|
|
|
|
Voir le fichier LICENSE
|
|
|
|
|
|
|
|
Ce programme permet de comparer le fichier des personnes décédées établi par l'INSEE avec les registre de membres de
|
|
|
|
l'Église, afin de déterminer si figurent dans nos registre des personnes décédées.
|
|
|
|
|
|
|
|
L'INSEE reçoit des communes les décès enregistrés. Le fichier des personnes décédées établi par l'INSEE est en accès
|
|
|
|
libre sur le site https://www.data.gouv.fr.
|
|
|
|
|
|
|
|
"""
|
2020-07-01 23:33:55 +02:00
|
|
|
import tkinter as tk
|
|
|
|
import tkinter.ttk as ttk
|
|
|
|
import tkinter.filedialog as tkfiledialog
|
2020-07-07 16:07:04 +02:00
|
|
|
from multiprocessing import Process, Pipe
|
2020-07-01 23:33:55 +02:00
|
|
|
|
|
|
|
from trouver_decedes import trouver_decedes
|
|
|
|
|
2020-07-17 21:49:45 +02:00
|
|
|
|
2020-07-01 23:33:55 +02:00
|
|
|
class MainApplication(tk.Frame):
|
|
|
|
def __init__(self, parent, *args, **kwargs):
|
2020-07-07 16:07:04 +02:00
|
|
|
# Worker
|
|
|
|
self.run = False
|
|
|
|
self.pipe = None
|
|
|
|
|
|
|
|
# GUI
|
2020-07-01 23:33:55 +02:00
|
|
|
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')
|
2020-07-29 09:56:37 +02:00
|
|
|
|
|
|
|
# Sélection fichier Excel
|
|
|
|
self.label_fichier_excel = tk.Label(self.frame, text="Fichier Excel")
|
|
|
|
self.label_fichier_excel.grid(row=1, column=0, sticky='e')
|
|
|
|
self.value_fichier_excel = tk.StringVar()
|
|
|
|
self.entry_fichier_excel = tk.Entry(self.frame, state='disabled', textvariable=self.value_fichier_excel)
|
|
|
|
self.entry_fichier_excel.grid(row=1, column=1, sticky='ew')
|
|
|
|
self.button_fichier_excel = tk.Button(self.frame, text="...", command=self.command_button_fichier_excel)
|
|
|
|
self.button_fichier_excel.grid(row=1, column=2, sticky='w')
|
2020-07-01 23:33:55 +02:00
|
|
|
|
|
|
|
# Sélection répertoire sortie
|
|
|
|
self.label_dir_out = tk.Label(self.frame, text="Répertoire de sortie")
|
2020-07-29 09:56:37 +02:00
|
|
|
self.label_dir_out.grid(row=2, column=0, sticky='e')
|
2020-07-01 23:33:55 +02:00
|
|
|
self.value_dir_out = tk.StringVar()
|
|
|
|
self.entry_dir_out = tk.Entry(self.frame, state='disabled', textvariable=self.value_dir_out)
|
2020-07-29 09:56:37 +02:00
|
|
|
self.entry_dir_out.grid(row=2, column=1, sticky='ew')
|
2020-07-01 23:33:55 +02:00
|
|
|
self.button_dir_out = tk.Button(self.frame, text="...", command=self.command_button_dir_out)
|
2020-07-29 09:56:37 +02:00
|
|
|
self.button_dir_out.grid(row=2, column=2, sticky='w')
|
2020-07-01 23:33:55 +02:00
|
|
|
|
|
|
|
# Sélection des unités à traiter
|
|
|
|
self.label_units = tk.Label(self.frame, text="Unités à purger")
|
2020-07-29 09:56:37 +02:00
|
|
|
self.label_units.grid(row=3, column=0, sticky='e')
|
2020-07-01 23:33:55 +02:00
|
|
|
self.value_units = tk.StringVar()
|
|
|
|
self.entry_units = tk.Entry(self.frame, textvariable=self.value_units)
|
2020-07-29 09:56:37 +02:00
|
|
|
self.entry_units.grid(row=3, column=1, sticky='ew', columnspan="2")
|
2020-07-01 23:33:55 +02:00
|
|
|
|
|
|
|
# Bouton validation
|
|
|
|
self.button_valid = tk.Button(self.frame, text="Ok", command=self.command_button_valid)
|
2020-07-29 09:56:37 +02:00
|
|
|
self.button_valid.grid(row=4, column=0, columnspan=3)
|
2020-07-01 23:33:55 +02:00
|
|
|
|
|
|
|
# Barre de progression
|
|
|
|
self.progressbar = ttk.Progressbar(self.frame, orient=tk.HORIZONTAL, mode='determinate')
|
2020-07-29 09:56:37 +02:00
|
|
|
self.progressbar.grid(row=5, column=0, columnspan=3, sticky='ew')
|
2020-07-01 23:33:55 +02:00
|
|
|
|
|
|
|
# Affichage des logs
|
|
|
|
self.text_log = tk.Text(self.frame, state='disabled')
|
2020-07-29 09:56:37 +02:00
|
|
|
self.text_log.grid(row=0, column=3, rowspan=6, sticky='nesw')
|
2020-07-01 23:33:55 +02:00
|
|
|
|
|
|
|
def command_button_bdd_insee(self):
|
|
|
|
self.value_bdd_insee.set(tkfiledialog.askopenfilename(title="Fichier de l'INSEE"))
|
|
|
|
|
2020-07-29 09:56:37 +02:00
|
|
|
def command_button_fichier_excel(self):
|
|
|
|
self.value_fichier_excel.set(tkfiledialog.askopenfilename(title="Fichier Excel"))
|
|
|
|
|
2020-07-01 23:33:55 +02:00
|
|
|
def command_button_dir_out(self):
|
|
|
|
self.value_dir_out.set(tkfiledialog.askdirectory(title="Répertoire de sortie"))
|
|
|
|
|
2020-07-07 16:07:04 +02:00
|
|
|
def add_log(self, text):
|
|
|
|
self.text_log.configure(state='normal')
|
|
|
|
self.text_log.insert(tk.END, text)
|
|
|
|
self.text_log.configure(state='disabled')
|
|
|
|
|
2020-07-29 09:56:37 +02:00
|
|
|
def clear_log(self):
|
|
|
|
self.text_log.configure(state='normal')
|
|
|
|
self.text_log.delete('1.0', tk.END)
|
|
|
|
self.text_log.configure(state='disabled')
|
|
|
|
|
2020-07-07 16:07:04 +02:00
|
|
|
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):
|
|
|
|
self.add_log(message['text'])
|
2020-07-29 09:56:37 +02:00
|
|
|
elif 'running' in message:
|
2020-07-07 16:07:04 +02:00
|
|
|
self.run = message['running']
|
|
|
|
elif message.get('set_max', False):
|
2020-07-28 16:51:42 +02:00
|
|
|
self.progressbar["value"] = 0
|
2020-07-07 16:07:04 +02:00
|
|
|
self.progressbar['maximum'] = message['set_max']
|
|
|
|
self.parent.after(100, self.watch)
|
|
|
|
else:
|
|
|
|
self.add_log("\nRecherche terminée\n")
|
|
|
|
self.button_valid.configure(state='normal')
|
|
|
|
|
|
|
|
def command_button_valid(self):
|
|
|
|
self.button_valid.configure(state='disabled')
|
2020-07-29 09:56:37 +02:00
|
|
|
self.clear_log()
|
2020-07-07 16:07:04 +02:00
|
|
|
self.run = True
|
|
|
|
(conn1, conn2) = Pipe()
|
|
|
|
self.pipe = conn1
|
2020-07-29 09:56:37 +02:00
|
|
|
unite = self.value_units.get().split(',')
|
|
|
|
if unite == ['']:
|
|
|
|
unite = None
|
|
|
|
Worker(conn2, self.value_bdd_insee.get(), self.value_fichier_excel.get(), self.value_dir_out.get(), unite).start()
|
2020-07-07 16:07:04 +02:00
|
|
|
self.watch()
|
|
|
|
|
|
|
|
|
|
|
|
class Worker(Process):
|
2020-07-29 09:56:37 +02:00
|
|
|
def __init__(self, pipe, bdd_insee, fichier_excel, dir_out, units):
|
2020-07-07 16:07:04 +02:00
|
|
|
Process.__init__(self)
|
|
|
|
self.pipe = pipe
|
|
|
|
self.bdd_insee = bdd_insee
|
2020-07-29 09:56:37 +02:00
|
|
|
self.fichier_excel = fichier_excel
|
2020-07-07 16:07:04 +02:00
|
|
|
self.dir_out = dir_out
|
|
|
|
self.units = units
|
|
|
|
|
|
|
|
def tracker(self, step=None, text=None, set_max=None, running=None):
|
2020-07-29 09:56:37 +02:00
|
|
|
if step is not None:
|
2020-07-07 16:07:04 +02:00
|
|
|
self.pipe.send({'step': step})
|
2020-07-29 09:56:37 +02:00
|
|
|
elif text is not None:
|
2020-07-07 16:07:04 +02:00
|
|
|
self.pipe.send({'text': text})
|
2020-07-29 09:56:37 +02:00
|
|
|
elif set_max is not None:
|
2020-07-07 16:07:04 +02:00
|
|
|
self.pipe.send({'set_max': set_max})
|
2020-07-29 09:56:37 +02:00
|
|
|
elif running is not None:
|
2020-07-07 16:07:04 +02:00
|
|
|
self.pipe.send({'running': running})
|
2020-07-01 23:33:55 +02:00
|
|
|
|
2020-07-07 16:07:04 +02:00
|
|
|
def run(self):
|
|
|
|
trouver_decedes(chemin_base_donnees=self.bdd_insee,
|
2020-07-29 09:56:37 +02:00
|
|
|
excel_path=self.fichier_excel,
|
2020-07-07 16:07:04 +02:00
|
|
|
chemin_repertoire_sortie=self.dir_out,
|
|
|
|
numeros_unites=self.units,
|
2020-07-01 23:33:55 +02:00
|
|
|
tracker=self.tracker)
|
2020-07-07 16:07:04 +02:00
|
|
|
self.pipe.send({'running': False})
|
2020-07-01 23:33:55 +02:00
|
|
|
|
2020-07-07 16:07:04 +02:00
|
|
|
|
2020-07-01 23:33:55 +02:00
|
|
|
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()
|