Bouton Quitter admin + boucle reconnexion caméra améliorée
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -828,17 +828,24 @@ class PB:
|
|||||||
if self.cam: self.cam.exit()
|
if self.cam: self.cam.exit()
|
||||||
except: pass
|
except: pass
|
||||||
self.cam = None; errs = 0
|
self.cam = None; errs = 0
|
||||||
while True:
|
_nb_retry = 0
|
||||||
time.sleep(3)
|
while _nb_retry < 10:
|
||||||
_usb_reset_done()
|
_nb_retry += 1
|
||||||
try:
|
time.sleep(3)
|
||||||
c = gp.Camera(); c.init()
|
_usb_reset_done()
|
||||||
self.cam = c; self.prev_actif = True
|
try:
|
||||||
print("Caméra reconnectée automatiquement")
|
c = gp.Camera(); c.init()
|
||||||
break
|
self.cam = c; self.prev_actif = True
|
||||||
except Exception as re:
|
print("Caméra reconnectée automatiquement")
|
||||||
print(f"Reconnexion échouée: {re}")
|
break
|
||||||
|
except Exception as re:
|
||||||
|
print(f"Reconnexion échouée ({_nb_retry}): {re}")
|
||||||
else:
|
else:
|
||||||
|
# 10 tentatives échouées → bascule en simulation
|
||||||
|
self.sim = True
|
||||||
|
print("Caméra introuvable → mode simulation")
|
||||||
|
errs = 0
|
||||||
|
else:
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
else:
|
else:
|
||||||
time.sleep(0.05)
|
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))
|
sq=self._txt("Scanner","xxs",T["texte2"],False); self.scr.blit(sq,(qx+100-sq.get_width()//2,qy+208))
|
||||||
# Boutons système
|
# Boutons système
|
||||||
y2=card.bottom+20
|
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
|
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
|
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_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("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("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("reboot").collidepoint(pos): subprocess.Popen(["sudo","reboot"])
|
||||||
elif R("shutdown").collidepoint(pos): subprocess.Popen(["sudo","shutdown","-h","now"])
|
elif R("shutdown").collidepoint(pos): subprocess.Popen(["sudo","shutdown","-h","now"])
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user