From 9c57c8f5f2a91d8055b9899c8d0101e3994fd28b Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 11 Apr 2026 19:14:51 +0200 Subject: [PATCH] =?UTF-8?q?Bouton=20Quitter=20admin=20+=20boucle=20reconne?= =?UTF-8?q?xion=20cam=C3=A9ra=20am=C3=A9lior=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Admin onglet Système : bouton Quitter (gris) pour fermer l'appli - Reconnexion caméra : max 10 tentatives (~30s) puis bascule en mode simulation ; le loop sim reprend la détection automatique toutes les 10s Co-Authored-By: Claude Sonnet 4.6 --- photobooth_pygame.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/photobooth_pygame.py b/photobooth_pygame.py index 08d3b17..1de7311 100644 --- a/photobooth_pygame.py +++ b/photobooth_pygame.py @@ -828,17 +828,24 @@ class PB: if self.cam: self.cam.exit() except: pass self.cam = None; errs = 0 - while True: - time.sleep(3) - _usb_reset_done() - try: - c = gp.Camera(); c.init() - self.cam = c; self.prev_actif = True - print("Caméra reconnectée automatiquement") - break - except Exception as re: - print(f"Reconnexion échouée: {re}") + _nb_retry = 0 + while _nb_retry < 10: + _nb_retry += 1 + time.sleep(3) + _usb_reset_done() + try: + c = gp.Camera(); c.init() + self.cam = c; self.prev_actif = True + print("Caméra reconnectée automatiquement") + break + except Exception as re: + print(f"Reconnexion échouée ({_nb_retry}): {re}") else: + # 10 tentatives échouées → bascule en simulation + self.sim = True + print("Caméra introuvable → mode simulation") + errs = 0 + else: time.sleep(0.3) else: time.sleep(0.05) @@ -1913,6 +1920,7 @@ class PB: sq=self._txt("Scanner","xxs",T["texte2"],False); self.scr.blit(sq,(qx+100-sq.get_width()//2,qy+208)) # Boutons système y2=card.bottom+20 + rq=pygame.Rect(W//2-540,y2,160,68); self._btn(rq,(80,80,80),"Quitter","sm"); btns["quitter"]=rq rb=pygame.Rect(W//2-360,y2,320,68); self._btn(rb,(255,152,0),"Redémarrer","sm"); btns["reboot"]=rb re=pygame.Rect(W//2+40,y2,320,68); self._btn(re,(244,67,54),"Éteindre","sm"); btns["shutdown"]=re @@ -2093,6 +2101,7 @@ class PB: elif R("lim_m").collidepoint(pos): self._admin_adj("compteur","limite",-50,50,9999) elif R("lim_p").collidepoint(pos): self._admin_adj("compteur","limite",+50,50,9999) elif R("reconnect_cam").collidepoint(pos): threading.Thread(target=self._reconnect_cam,daemon=True).start() + elif R("quitter").collidepoint(pos): running=False elif R("reboot").collidepoint(pos): subprocess.Popen(["sudo","reboot"]) elif R("shutdown").collidepoint(pos): subprocess.Popen(["sudo","shutdown","-h","now"]) else: