Skip to content
Snippets Groups Projects
Commit 46b101b5 authored by BIRK Renaud's avatar BIRK Renaud
Browse files

Ajout de l'interface graphique

parent 34ab0bea
No related branches found
No related tags found
No related merge requests found
......@@ -11,4 +11,5 @@ et le projet adhère au [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Ajout de l'OCR.
- Ajout de l'identification.
- Ajout de l'interface graphique.
- Ajout d'un fichier de test.
......@@ -4,9 +4,10 @@ ou prothèse à partir des informations présentes sur son emballage.
"""
__all__ = [
"Device", "Group", "Identification", "OCR"
"Device", "Group", "Identification", "OCR", "UI"
]
from ._identification import Identification
from ._models import Device, Group
from ._ocr import OCR
from ._ui import UI
......@@ -22,10 +22,10 @@ class Group:
class Device:
"""
Classe représentant les informations d'identification d'un dispositif.
:param uid: L'identificateur unique (IUD)
:param manufacturer_name: Le fabricant
:param brand_name: La marque
:param description: Une description
:param uid: L'identificateur unique (IUD)
:param ref: La référence
:param useful_groups: La liste de groupes à trier
"""
......
......
from ._models import *
from tkinter import *
class UI:
"""
Classe définissant une interface graphique remplie à l'issue de la phase
d'identification.
:param device: Un dispositif issu de la phase d'identification
:param export_path: Un chemin d'exportation
"""
def __init__(self, device: Device, export_path: str=None) -> None:
self.device = device
self.export_path = export_path
def clear(self) -> None:
"""
Nettoie la fenêtre.
"""
for widget in self.app.winfo_children():
widget.grid_forget()
def draw(self) -> None:
"""
Dessine les composants sur la fenêtre.
"""
# S'il n'y a plus d'élements à trier, on arrête l'application
if not len(self.device.useful_groups):
self.export()
self.app.destroy()
return
word_entry = Entry(self.app, justify='center', width=70)
word_entry.insert(0, self.device.useful_groups.pop(0).string)
word_entry.grid(row=1, column=1, columnspan=4)
uid_button = Button(self.app, text="IUD", command=lambda: self.updateField(uid_entry=word_entry))
uid_button.grid(row=2, column=1)
manufacturer_button = Button(self.app, text="Fabricant", command=lambda: self.updateField(manufacturer_name_entry=word_entry))
manufacturer_button.grid(row=2, column=2)
brand_button = Button(self.app, text="Marque", command=lambda: self.updateField(brand_name_entry=word_entry))
brand_button.grid(row=2, column=3)
ref_button = Button(self.app, text="Reférence", command=lambda: self.updateField(ref_entry=word_entry))
ref_button.grid(row=2, column=4)
uid_entry = Entry(self.app, justify='center', width=20)
uid_entry.insert(0, self.device.uid)
uid_entry.grid(row=3, column=1)
manufacturer_name_entry = Entry(self.app, justify='center', width=20)
manufacturer_name_entry.insert(0, self.device.manufacturer_name)
manufacturer_name_entry.grid(row=3, column=2)
brand_name_entry = Entry(self.app, justify='center', width=20)
brand_name_entry.insert(0, self.device.brand_name)
brand_name_entry.grid(row=3, column=3)
ref_entry = Entry(self.app, justify='center', width=20)
ref_entry.insert(0, self.device.ref)
ref_entry.grid(row=3, column=4)
description_button = Button(self.app, text="Description", command = lambda: self.updateField(description=word_entry))
description_button.grid(row=4, column=2, columnspan=2)
trash_button = Button(self.app, text="Poubelle", command = self.updateField)
trash_button.grid(row=4, column=1)
exit_button = Button(self.app, text="Quitter", command = lambda: (self.export, self.app.destroy))
exit_button.grid(row=4, column=4)
def export(self) -> None:
"""
Si le chemin d'export du fichier est défini on exporte le fichier au
format de dictionnaire Python.
"""
if self.export_path:
file = open(self.export_path, "w")
file.write(str(self.device))
file.close()
def show(self) -> None:
"""
Initialise et affiche la fenêtre.
"""
self.app = Tk()
self.app.eval('tk::PlaceWindow . center')
self.app.geometry("620x240")
self.app.grid()
self.app.columnconfigure(1, minsize=150)
self.app.columnconfigure(2, minsize=150)
self.app.columnconfigure(3, minsize=150)
self.app.columnconfigure(4, minsize=150)
self.app.rowconfigure(1, minsize=60)
self.app.rowconfigure(2, minsize=60)
self.app.rowconfigure(3, minsize=60)
self.app.rowconfigure(4, minsize=60)
self.draw()
self.app.mainloop()
def updateField(self, uid_entry: Entry=None, manufacturer_name_entry: Entry=None, brand_name_entry: Entry=None, ref_entry: Entry=None, description: str=None) -> None:
"""
Met à jour les champs du dispositif selon les informations remplies
dans les composants de la fenêtre.
:param uid_entry: Champ de texte de l'IUD
:param manufacturer_name_entry: Champ de texte du fabricant
:param brand_name_entry: Champ de texte de la marque
:param ref_entry: Champ de texte de la référence
:param description: Description
"""
if uid_entry:
self.device.uid = uid_entry.get()
if manufacturer_name_entry:
self.device.manufacturer_name = manufacturer_name_entry.get()
if brand_name_entry:
self.device.brand_name = brand_name_entry.get()
if ref_entry:
self.device.ref = ref_entry.get()
if description:
self.device.description += description.get() + "\n"
self.clear()
self.draw()
......@@ -31,31 +31,36 @@ def main():
# 2 bis. Génération des images
ocr.save_ocr(device.useful_groups, TEST_IMAGES_DIR + "/biomet.jpg", OUTPUT_DIR + "/biomet_export_step2.jpg", FONT_DIR + "/" + FONT_FILENAME)
# 3. Interface graphique de tri
UI(device, OUTPUT_DIR + "/biomet_export_step3.txt").show()
# Autres exemples
groups2 = ocr.recognize(TEST_IMAGES_DIR + "/passeo-18.jpg")
ocr.save_ocr(groups2, TEST_IMAGES_DIR + "/passeo-18.jpg", OUTPUT_DIR + "/passeo-18_export_step1.jpg", FONT_DIR + "/" + FONT_FILENAME)
file2 = open(OUTPUT_DIR + "/passeo-18_export_step1.txt", "w")
file2.write(str(groups2))
file2.close()
identification2 = Identification(groups2)
device2 = identification2.identify()
output_file2 = open(OUTPUT_DIR + "/passeo-18_export_step2.txt", "w")
output_file2.write(str(device2))
output_file2.close()
ocr.save_ocr(device2.useful_groups, TEST_IMAGES_DIR + "/passeo-18.jpg", OUTPUT_DIR + "/passeo-18_export_step2.jpg", FONT_DIR + "/" + FONT_FILENAME)
groups3 = ocr.recognize(TEST_IMAGES_DIR + "/stryker.jpg")
ocr.save_ocr(groups3, TEST_IMAGES_DIR + "/stryker.jpg", OUTPUT_DIR + "/stryker_export_step1.jpg", FONT_DIR + "/" + FONT_FILENAME)
file3 = open(OUTPUT_DIR + "/stryker_export_step1.txt", "w")
file3.write(str(groups3))
file3.close()
identification3 = Identification(groups3)
device3 = identification3.identify()
output_file3 = open(OUTPUT_DIR + "/stryker_export_step2.txt", "w")
output_file3.write(str(device3))
output_file3.close()
ocr.save_ocr(device3.useful_groups, TEST_IMAGES_DIR + "/stryker.jpg", OUTPUT_DIR + "/stryker_export_step2.jpg", FONT_DIR + "/" + FONT_FILENAME)
# groups2 = ocr.recognize(TEST_IMAGES_DIR + "/passeo-18.jpg")
# ocr.save_ocr(groups2, TEST_IMAGES_DIR + "/passeo-18.jpg", OUTPUT_DIR + "/passeo-18_export_step1.jpg", FONT_DIR + "/" + FONT_FILENAME)
# file2 = open(OUTPUT_DIR + "/passeo-18_export_step1.txt", "w")
# file2.write(str(groups2))
# file2.close()
# identification2 = Identification(groups2)
# device2 = identification2.identify()
# output_file2 = open(OUTPUT_DIR + "/passeo-18_export_step2.txt", "w")
# output_file2.write(str(device2))
# output_file2.close()
# ocr.save_ocr(device2.useful_groups, TEST_IMAGES_DIR + "/passeo-18.jpg", OUTPUT_DIR + "/passeo-18_export_step2.jpg", FONT_DIR + "/" + FONT_FILENAME)
# UI(device2, OUTPUT_DIR + "/passeo-18_export_step3.txt").show()
# groups3 = ocr.recognize(TEST_IMAGES_DIR + "/stryker.jpg")
# ocr.save_ocr(groups3, TEST_IMAGES_DIR + "/stryker.jpg", OUTPUT_DIR + "/stryker_export_step1.jpg", FONT_DIR + "/" + FONT_FILENAME)
# file3 = open(OUTPUT_DIR + "/stryker_export_step1.txt", "w")
# file3.write(str(groups3))
# file3.close()
# identification3 = Identification(groups3)
# device3 = identification3.identify()
# output_file3 = open(OUTPUT_DIR + "/stryker_export_step2.txt", "w")
# output_file3.write(str(device3))
# output_file3.close()
# ocr.save_ocr(device3.useful_groups, TEST_IMAGES_DIR + "/stryker.jpg", OUTPUT_DIR + "/stryker_export_step2.jpg", FONT_DIR + "/" + FONT_FILENAME)
# UI(device3, OUTPUT_DIR + "/stryker_export_step3.txt").show()
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment