Fix API gphoto2 pour python-gphoto2 v2.5+ (suppression contexte)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,9 +75,8 @@ class Camera:
|
|||||||
if source == "gphoto2" or source is None:
|
if source == "gphoto2" or source is None:
|
||||||
if GPHOTO2_DISPONIBLE:
|
if GPHOTO2_DISPONIBLE:
|
||||||
try:
|
try:
|
||||||
self.contexte = gp.Context()
|
|
||||||
self.camera = gp.Camera()
|
self.camera = gp.Camera()
|
||||||
self.camera.init(self.contexte)
|
self.camera.init()
|
||||||
self.connectee = True
|
self.connectee = True
|
||||||
self.mode = "gphoto2"
|
self.mode = "gphoto2"
|
||||||
log.info("Camera DSLR connectee")
|
log.info("Camera DSLR connectee")
|
||||||
@@ -116,7 +115,7 @@ class Camera:
|
|||||||
"""Deconnecte l'appareil photo."""
|
"""Deconnecte l'appareil photo."""
|
||||||
if self.camera and GPHOTO2_DISPONIBLE:
|
if self.camera and GPHOTO2_DISPONIBLE:
|
||||||
try:
|
try:
|
||||||
self.camera.exit(self.contexte)
|
self.camera.exit()
|
||||||
except gp.GPhoto2Error:
|
except gp.GPhoto2Error:
|
||||||
pass
|
pass
|
||||||
if self.webcam:
|
if self.webcam:
|
||||||
@@ -148,9 +147,10 @@ class Camera:
|
|||||||
|
|
||||||
def _capture_gphoto2(self, chemin_dest: Path) -> Path | None:
|
def _capture_gphoto2(self, chemin_dest: Path) -> Path | None:
|
||||||
try:
|
try:
|
||||||
chemin_camera = self.camera.capture(gp.GP_CAPTURE_IMAGE, self.contexte)
|
chemin_camera = self.camera.capture(gp.GP_CAPTURE_IMAGE)
|
||||||
fichier_camera = self.camera.file_get(
|
fichier_camera = gp.CameraFile()
|
||||||
chemin_camera.folder, chemin_camera.name, gp.GP_FILE_TYPE_NORMAL, self.contexte
|
self.camera.file_get(
|
||||||
|
chemin_camera.folder, chemin_camera.name, gp.GP_FILE_TYPE_NORMAL, fichier_camera
|
||||||
)
|
)
|
||||||
fichier_camera.save(str(chemin_dest))
|
fichier_camera.save(str(chemin_dest))
|
||||||
log.info(f"Photo capturee (DSLR) : {chemin_dest}")
|
log.info(f"Photo capturee (DSLR) : {chemin_dest}")
|
||||||
@@ -184,7 +184,7 @@ class Camera:
|
|||||||
|
|
||||||
def _preview_gphoto2(self) -> bytes | None:
|
def _preview_gphoto2(self) -> bytes | None:
|
||||||
try:
|
try:
|
||||||
fichier = self.camera.capture_preview(self.contexte)
|
fichier = self.camera.capture_preview()
|
||||||
donnees = fichier.get_data_and_size()
|
donnees = fichier.get_data_and_size()
|
||||||
return bytes(donnees)
|
return bytes(donnees)
|
||||||
except gp.GPhoto2Error as e:
|
except gp.GPhoto2Error as e:
|
||||||
@@ -215,8 +215,7 @@ class Camera:
|
|||||||
# DSLR via gphoto2
|
# DSLR via gphoto2
|
||||||
if GPHOTO2_DISPONIBLE:
|
if GPHOTO2_DISPONIBLE:
|
||||||
try:
|
try:
|
||||||
ctx = self.contexte or gp.Context()
|
dslrs = gp.Camera.autodetect()
|
||||||
dslrs = gp.Camera.autodetect(ctx)
|
|
||||||
for nom, port in dslrs:
|
for nom, port in dslrs:
|
||||||
appareils.append({
|
appareils.append({
|
||||||
"nom": f"{nom} ({port})",
|
"nom": f"{nom} ({port})",
|
||||||
|
|||||||
Reference in New Issue
Block a user