diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..3e99ede35449c19657050b5668845a4690f035b3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "." + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/Code_objets/__pycache__/Display.cpython-310.pyc b/Code_objets/__pycache__/Display.cpython-310.pyc index b2170e9591314447e8a13d70e170b9cae774f34b..ce8f04f19664a039fe127ec94b25b6607f4ace33 100644 Binary files a/Code_objets/__pycache__/Display.cpython-310.pyc and b/Code_objets/__pycache__/Display.cpython-310.pyc differ diff --git a/Code_objets/__pycache__/ImageProcessing.cpython-310.pyc b/Code_objets/__pycache__/ImageProcessing.cpython-310.pyc index 08735fde6bd45504c90013cab1f8dcb071789803..c99760e2bcecd0066e7f4f9d7b9ae4529e83bce2 100644 Binary files a/Code_objets/__pycache__/ImageProcessing.cpython-310.pyc and b/Code_objets/__pycache__/ImageProcessing.cpython-310.pyc differ diff --git a/Code_objets/__pycache__/Main.cpython-310.pyc b/Code_objets/__pycache__/Main.cpython-310.pyc index 68af849b8fc70a0c48ed4b41d9d702408da65197..a0b1bc93be8307a1b2f8d23e2810a75c30885253 100644 Binary files a/Code_objets/__pycache__/Main.cpython-310.pyc and b/Code_objets/__pycache__/Main.cpython-310.pyc differ diff --git a/Code_objets/__pycache__/Menu.cpython-310.pyc b/Code_objets/__pycache__/Menu.cpython-310.pyc index d58ad8dfad2736a4aa7de1d20331852235f347a7..ce9d7b57e75225fab452216fc37fa6b650f79b01 100644 Binary files a/Code_objets/__pycache__/Menu.cpython-310.pyc and b/Code_objets/__pycache__/Menu.cpython-310.pyc differ diff --git a/Code_objets/__pycache__/Parameters.cpython-310.pyc b/Code_objets/__pycache__/Parameters.cpython-310.pyc index a1fef98059f7080b27dd78b68da050f302d94867..b0b5de2665bbbec468cb0efca8cf3ece29f80928 100644 Binary files a/Code_objets/__pycache__/Parameters.cpython-310.pyc and b/Code_objets/__pycache__/Parameters.cpython-310.pyc differ diff --git a/Code_objets/__pycache__/Point.cpython-310.pyc b/Code_objets/__pycache__/Point.cpython-310.pyc index 9439b4b96538d8fb0358552264e1412cc94e2503..8bddbd546715215a73f05cd2f67bd9f319f53228 100644 Binary files a/Code_objets/__pycache__/Point.cpython-310.pyc and b/Code_objets/__pycache__/Point.cpython-310.pyc differ diff --git a/Code_objets/__pycache__/Trajectory.cpython-310.pyc b/Code_objets/__pycache__/Trajectory.cpython-310.pyc index 074bc8f3824d01f6628aa6e2931e66119f1012d4..6e420dad93b877411490387262f423ac887e6b80 100644 Binary files a/Code_objets/__pycache__/Trajectory.cpython-310.pyc and b/Code_objets/__pycache__/Trajectory.cpython-310.pyc differ diff --git a/Code_objets/__pycache__/UI.cpython-310.pyc b/Code_objets/__pycache__/UI.cpython-310.pyc index d24001918bbdac43b390957180891882d316a121..d26ef227592781f64a23482cc23af63b687e5f37 100644 Binary files a/Code_objets/__pycache__/UI.cpython-310.pyc and b/Code_objets/__pycache__/UI.cpython-310.pyc differ diff --git a/Code_objets/__pycache__/VideoManager.cpython-310.pyc b/Code_objets/__pycache__/VideoManager.cpython-310.pyc index 96cd74133fa8fe645feb42105a8e077505bfff2f..5d76ee88c89b7894e9d867b2fa10899bd4c1b2e7 100644 Binary files a/Code_objets/__pycache__/VideoManager.cpython-310.pyc and b/Code_objets/__pycache__/VideoManager.cpython-310.pyc differ diff --git a/Objet/__pycache__/main.cpython-310.pyc b/Objet/__pycache__/main.cpython-310.pyc index 5cc024724307d9d45be4574c2b3f472aaa136ee6..d0b4158647e682823c630cad49ac967424325081 100644 Binary files a/Objet/__pycache__/main.cpython-310.pyc and b/Objet/__pycache__/main.cpython-310.pyc differ diff --git a/Objet/__pycache__/menu.cpython-310.pyc b/Objet/__pycache__/menu.cpython-310.pyc index 995153ef28663e9975adb7abe4c3546fa8d2f720..83015087dea9d2d6546eccdd7ddb7b9648a3198e 100644 Binary files a/Objet/__pycache__/menu.cpython-310.pyc and b/Objet/__pycache__/menu.cpython-310.pyc differ diff --git a/Objet/__pycache__/trajectory.cpython-310.pyc b/Objet/__pycache__/trajectory.cpython-310.pyc index 35ca0cd65d6446c011005698b7cdd58aba4f8d3a..4f22c7283a097c3f0f0c0ab9fec80bb9bac23711 100644 Binary files a/Objet/__pycache__/trajectory.cpython-310.pyc and b/Objet/__pycache__/trajectory.cpython-310.pyc differ diff --git a/Objet/__pycache__/ui.cpython-310.pyc b/Objet/__pycache__/ui.cpython-310.pyc index 403d169a1c35e1a378410a8362e2153cfbedd86a..64e48af625d2e8ce57e84cb50d9d8a511d05fcf1 100644 Binary files a/Objet/__pycache__/ui.cpython-310.pyc and b/Objet/__pycache__/ui.cpython-310.pyc differ diff --git a/__pycache__/test_chargement.cpython-310-pytest-8.3.5.pyc b/__pycache__/test_chargement.cpython-310-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bed2af3036449cfaded3317402fe03f409368ef1 Binary files /dev/null and b/__pycache__/test_chargement.cpython-310-pytest-8.3.5.pyc differ diff --git a/__pycache__/test_chercherdossier.cpython-310-pytest-8.3.5.pyc b/__pycache__/test_chercherdossier.cpython-310-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..25417afddbde93e39f88d3e1f99cdcb58df095c4 Binary files /dev/null and b/__pycache__/test_chercherdossier.cpython-310-pytest-8.3.5.pyc differ diff --git a/__pycache__/test_multithrading_logo.cpython-310-pytest-8.3.5.pyc b/__pycache__/test_multithrading_logo.cpython-310-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5c0355b28dae0907d99d34d4ef2e093187125f88 Binary files /dev/null and b/__pycache__/test_multithrading_logo.cpython-310-pytest-8.3.5.pyc differ diff --git a/__pycache__/test_nouveautestthreding.cpython-310-pytest-8.3.5.pyc b/__pycache__/test_nouveautestthreding.cpython-310-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..574f08c449b1eaa692997d1b9f2c514422cc3c8e Binary files /dev/null and b/__pycache__/test_nouveautestthreding.cpython-310-pytest-8.3.5.pyc differ diff --git a/__pycache__/test_recup_info.cpython-310-pytest-8.3.5.pyc b/__pycache__/test_recup_info.cpython-310-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e33a043a73459068f6c2832c2b52352e981474d7 Binary files /dev/null and b/__pycache__/test_recup_info.cpython-310-pytest-8.3.5.pyc differ diff --git a/multithreading.py b/multithreading.py index a9d20f607ae682ac7803283aa489529e81e3177a..5d2d61e3ca7f74ba0ac19c355be5cb3fbcdc78db 100644 --- a/multithreading.py +++ b/multithreading.py @@ -1,29 +1,39 @@ import time import threading -# Fonction simulant une tâche lourde (ex: traitement d'image, calculs intensifs) -def tache_lourde(): +# Fonction qui effectue une partie du travail +def tache_lourde(part_debut, part_fin, resultat, index): somme = 0 - for _ in range(10**7): # Boucle qui prend un certain temps + for i in range(part_debut, part_fin): somme += 1 - return somme + resultat[index] = somme # Stocker le résultat pour éviter la concurrence + +# Paramètres +N = 10**7 # Taille du travail total +THREADS = 4 # Nombre de threads à utiliser # Exécution sans multithreading start = time.time() -for _ in range(4): # Exécuter 4 tâches séquentiellement - tache_lourde() +somme_total = sum(range(N)) # Exécution en une seule fois end = time.time() print(f"Temps sans multithreading: {end - start:.2f} secondes") # Exécution avec multithreading start = time.time() threads = [] -for _ in range(4): # Lancer 4 threads en parallèle - thread = threading.Thread(target=tache_lourde) +resultats = [0] * THREADS # Stocker les résultats des threads +portion = N // THREADS # Taille de la charge par thread + +for i in range(THREADS): + debut = i * portion + fin = N if i == THREADS - 1 else (i + 1) * portion + thread = threading.Thread(target=tache_lourde, args=(debut, fin, resultats, i)) threads.append(thread) thread.start() for thread in threads: - thread.join() # Attendre que tous les threads finissent + thread.join() # Attendre la fin de tous les threads + +somme_total_thread = sum(resultats) # Fusionner les résultats end = time.time() print(f"Temps avec multithreading: {end - start:.2f} secondes") diff --git a/test_chargement.py b/test_chargement.py index a7ed873ba88da90e8dc3376948511c0402c98810..3283d09869ec1fb332801927d1c906aa4f18eb7f 100644 --- a/test_chargement.py +++ b/test_chargement.py @@ -1,9 +1,11 @@ import time +import threading +import os +import sys from tkinter import Tk, Label from PIL import Image, ImageTk # Installer Pillow si nécessaire : pip install pillow -# Lancer ton programme principal ici - +# --- Création du Splash Screen --- splash = Tk() splash.overrideredirect(True) # Enlever la barre de titre @@ -22,30 +24,30 @@ splash.geometry(f"{img_width}x{img_height}+{x_pos}+{y_pos}") # Afficher l'image label = Label(splash, image=photo) label.pack() +splash.update() # Mise à jour de l'affichage -# Garder le splash pendant le chargement -splash.update() - -# Pour éviter que le programme ne se ferme instantanément - - - -import os -import sys +# --- Fonction pour charger le menu principal --- +def charger_menu(): + global splash + base_dir = os.path.dirname(os.path.abspath(__file__)) + dossier_path = os.path.join(base_dir, 'Objet') + sys.path.append(dossier_path) + import menu # Importer ici pour éviter les blocages + temps = time.time() + + a = menu.App() # Chargement du menu + splash.destroy() # Fermer le splash après le chargement -# Fermer le splash et ouvrir le menu principal -base_dir = os.path.dirname(os.path.abspath(__file__)) + tmp = time.time() + print(f"Temps d'exécution : {-(temps - tmp):.6f} secondes") -dossier_path = os.path.join(base_dir,'Objet') -sys.path.append(dossier_path) + a.mainloop() # Lancer l'application principale + -import menu -temps = time.time() -a = menu.App() -splash.destroy() -tmp = time.time() -a.mainloop() +# --- Lancer le chargement en arrière-plan --- +thread = threading.Thread(target=charger_menu) +thread.start() -tot = temps - tmp -print(f"Temps d'exécution : {-tot:.6f} secondes") \ No newline at end of file +# --- Affichage du splash screen pendant le chargement --- +splash.mainloop() diff --git a/test_chercherdossier.py b/test_chercherdossier.py index b38b9876adbd58be61ca6ca1d6d20b0e8377cddb..4b59e22711c326131b318c0f21a1f25c1bf584a0 100644 --- a/test_chercherdossier.py +++ b/test_chercherdossier.py @@ -1,11 +1,39 @@ import os import sys +import time +import threading +import os +import sys +from tkinter import Tk, Label +from PIL import Image, ImageTk # Installer Pillow si nécessaire : pip install pillow + +# --- Création du Splash Screen --- +splash = Tk() +splash.overrideredirect(True) # Enlever la barre de titre + +# Charger l'image +image = Image.open("LogoSymbole_canard.png") +photo = ImageTk.PhotoImage(image) + +# Définir la taille et centrer +screen_width = splash.winfo_screenwidth() +screen_height = splash.winfo_screenheight() +img_width, img_height = image.size +x_pos = (screen_width - img_width) // 2 +y_pos = (screen_height - img_height) // 2 +splash.geometry(f"{img_width}x{img_height}+{x_pos}+{y_pos}") + +# Afficher l'image +label = Label(splash, image=photo) +label.pack() +splash.update() # Mise à jour de l'affichage base_dir = os.path.dirname(os.path.abspath(__file__)) -dossier_path = os.path.join(base_dir,'Code_objets') +dossier_path = os.path.join(base_dir,'Objet') sys.path.append(dossier_path) -import Menu -a = Menu.App() +import menu +a = menu.App() +splash.destroy() a.mainloop() diff --git a/test_multithrading_logo.py b/test_multithrading_logo.py index 57a1d5a06b8925cd523c943bd79d64bc3ecae4f9..6d58413ba07346e1310d55f1fb762aaff96aa435 100644 --- a/test_multithrading_logo.py +++ b/test_multithrading_logo.py @@ -3,20 +3,17 @@ from PIL import Image, ImageTk import threading import time - - -# Fonction pour afficher le splash screen def show_splash(): - global splash # Garder une référence à la fenêtre + global splash, photo splash = tk.Tk() - splash.overrideredirect(True) # Enlever la barre de titre + splash.overrideredirect(True) # Charger l'image - image = Image.open("LogoSymbole_canard.png") # Remplace par ton logo + image = Image.open("LogoSymbole_canard.png") photo = ImageTk.PhotoImage(image) - # Définir la taille et centrer + # Centrer la fenêtre screen_width = splash.winfo_screenwidth() screen_height = splash.winfo_screenheight() img_width, img_height = image.size @@ -24,40 +21,41 @@ def show_splash(): y_pos = (screen_height - img_height) // 2 splash.geometry(f"{img_width}x{img_height}+{x_pos}+{y_pos}") - # Afficher l'image label = tk.Label(splash, image=photo) + label.image = photo # Évite la suppression de l'image par le garbage collector label.pack() - splash.update() - splash.mainloop() # Garde la fenêtre active jusqu'à ce qu'on la ferme + # Lancer le thread du programme principal + global main_thread + main_thread = threading.Thread(target=load_main_program, daemon=True) + main_thread.start() -# Fonction pour charger le programme principal -def load_main_program(): - time.sleep(3) # Simule un chargement + # Vérifier périodiquement si le programme principal est chargé + splash.after(100, check_thread) - # Fermer l'écran de chargement - splash.destroy() + splash.mainloop() +def load_main_program(): + """Charge le programme principal (menu.App), sans interaction directe avec Tkinter.""" import os - import sys + import sys + base_dir = os.path.dirname(os.path.abspath(__file__)) - - dossier_path = os.path.join(base_dir,'Objet') + dossier_path = os.path.join(base_dir, 'Objet') sys.path.append(dossier_path) - import menu + global app + app = menu.App() # Instanciation de l'application +def check_thread(): + """Vérifie si le thread principal a fini de charger le programme.""" + if not main_thread.is_alive(): + splash.destroy() # Fermer le splash + app.mainloop() # Lancer l'application principale dans le thread principal + else: + splash.after(100, check_thread) # Vérifier à nouveau après 100 ms - # Lancer le programme principal ici - a = menu.App() - a.mainloop() - -# Démarrer le splash screen dans un thread -splash_thread = threading.Thread(target=show_splash) -splash_thread.start() - -# Charger le programme principal dans un autre thread -main_thread = threading.Thread(target=load_main_program) -main_thread.start() +# Démarrer le splash screen dans le thread principal +show_splash() diff --git a/test_nouveautestthreding.py b/test_nouveautestthreding.py new file mode 100644 index 0000000000000000000000000000000000000000..31ab9c990d82748fe441173c443491a04eae997d --- /dev/null +++ b/test_nouveautestthreding.py @@ -0,0 +1,48 @@ +import threading +import time + +# Function to perform a computational task +def compute_task(start, end): + total = 0 + for i in range(start, end): + total += i ** 2 + return total + +# Wrapper function for threading +def thread_wrapper(start, end, results, index): + results[index] = compute_task(start, end) + +# Single-threaded execution +def single_threaded(): + start_time = time.time() + compute_task(0, 10_000_000) + end_time = time.time() + return end_time - start_time + +# Multi-threaded execution +def multi_threaded(): + start_time = time.time() + num_threads = 4 + step = 10_000_000 // num_threads + threads = [] + results = [0] * num_threads + + for i in range(num_threads): + t = threading.Thread(target=thread_wrapper, args=(i * step, (i + 1) * step, results, i)) + threads.append(t) + t.start() + + for t in threads: + t.join() + + end_time = time.time() + return end_time - start_time + +# Main function to compare performance +if __name__ == "__main__": + single_thread_time = single_threaded() + multi_thread_time = multi_threaded() + + print(f"Single-threaded execution time: {single_thread_time:.4f} seconds") + print(f"Multi-threaded execution time: {multi_thread_time:.4f} seconds") + print("Multi-threading is faster!" if multi_thread_time < single_thread_time else "Single-threading is faster!") \ No newline at end of file diff --git a/volley_mire_detection/scripts/__pycache__/test_model.cpython-310-pytest-8.3.5.pyc b/volley_mire_detection/scripts/__pycache__/test_model.cpython-310-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cc5e0a6d21db85a3c4a6ef9154bc067e9bda0a95 Binary files /dev/null and b/volley_mire_detection/scripts/__pycache__/test_model.cpython-310-pytest-8.3.5.pyc differ