diff --git a/main.py b/main.py index c8e8fac..fd62b68 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,10 @@ import os +import time from PIL import Image import pygame import threading +from watchdog.observers import Observer +from watchdog.events import FileSystemEventHandler # Chemin vers le dossier contenant les images IMAGE_DIR = './photos' @@ -36,12 +39,14 @@ previous_logo_rect = previous_logo.get_rect(midleft=(screen.get_rect().left + 20 # Chargement des images dans une liste images = [] + # Fonction pour charger une image en utilisant un thread def load_image(image_path): with Image.open(image_path) as img: img.thumbnail(screen.get_size()) images.append(pygame.image.fromstring(img.tobytes(), img.size, "RGB")) + # Création des threads pour charger les images image_threads = [] for file_name in os.listdir(IMAGE_DIR): @@ -55,6 +60,30 @@ for file_name in os.listdir(IMAGE_DIR): for image_thread in image_threads: image_thread.join() + +class ImageHandler(FileSystemEventHandler): + def on_modified(self, event): + if event.src_path.endswith('.jpg') or event.src_path.endswith('.png'): + load_image(event.src_path) + +def watch_images_directory(): + event_handler = ImageHandler() + observer = Observer() + observer.schedule(event_handler, IMAGE_DIR, recursive=False) + observer.start() + + try: + while True: + time.sleep(1) + except KeyboardInterrupt: + observer.stop() + observer.join() + + +watch_thread = threading.Thread(target=watch_images_directory) +watch_thread.daemon = True +watch_thread.start() + # Définition des zones d'affichage screen_width, screen_height = screen.get_size() left_rect = pygame.Rect(0, 0, screen_width // 3, screen_height) diff --git a/photos/matthew-buchanan-g-0dp2ycCw0.jpg b/photos/matthew-buchanan-g-0dp2ycCw0.jpg new file mode 100644 index 0000000..1f69599 Binary files /dev/null and b/photos/matthew-buchanan-g-0dp2ycCw0.jpg differ diff --git a/photos/neil-nourigat-tT3CGmnR1pk.jpg b/photos/neil-nourigat-tT3CGmnR1pk.jpg new file mode 100644 index 0000000..e45514e Binary files /dev/null and b/photos/neil-nourigat-tT3CGmnR1pk.jpg differ