capture_preview() broken in v2.5.0
Closed this issue · 4 comments
Problem:
After updating to v2.5.0 my code is broken.
Minimal working example:
Fails in line 8 cap.capture_preview(ctxt)
.
import gphoto2 as gp
ctxt = gp.Context()
cap = gp.Camera()
cap.init(ctxt)
camera_file = cap.capture_preview(ctxt)
file_data = camera_file.get_data_and_size()
cap.exit(ctxt)
Error message:
File "____.py", line 8, in <module>
camera_file = cap.capture_preview(ctxt)
TypeError: in method 'Camera_capture_preview', argument 2 of type 'CameraFile *'
I am using python_3.10.12.
Background:
I was doing a ubuntu dist update, which erased my pip dependencies. Then I did pip install gphoto2
(got me v2.5.0) and my code was broken.
As written in the Changelog, there were changes in capture_preview()
: "Parameter CameraFile Optional"
I verified by installing v2.4.0 that my example code worked before.
What do I need to do to get my code working again? What parameter do I have to pass to capture_preview()?
This is because capture_preview
now has two optional parameters - a CameraFile
and a Context
(or GPContext
). If you need to pass a Context
you also need to pass a CameraFile
, which can be created with camera_file = gp.CameraFile()
. In this case the CameraFile
object is not returned by capture_preview
.
The "pythonic" way to do this would be with named/keyword parameters. I'll investigate if I can do this with SWIG.
You don't normally need a Context
- it's only used if you need callbacks during some functions.
You can also use None
instead of a CameraFile
object. capture_preview
will then behave as before, returning a new CameraFile
object.
The "pythonic" way to do this would be with named/keyword parameters. I'll investigate if I can do this with SWIG.
SWIG can create keyword arguments, but it's an all or nothing option. Changing all python-gphoto2 function arguments to keyword arguments would be a big change (and wouldn't allow overloaded functions that are currently used).
Great! Thanks for the instant response!
Passing None
instead of CameraFile
works.
Thanks also for the hint of not needing a Context
. I removed this variable entirely and it still works :)