jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
357 stars 59 forks source link

[QUESTION] Help with setting single config #137

Closed mexicantexan closed 2 years ago

mexicantexan commented 2 years ago

I am trying to set the autofocus area for my Nikon D7200

I retrieved the config object and saw this entry in it:

{
          "idx": "6,6,0,0",
          "ro": 0,
          "name": "changeafarea",
          "label": "Set Nikon Autofocus area",
          "type": 2,
          "typestr": "GP_WIDGET_TEXT",
          "value": "0x0"
 },

I'm not quite sure what parameters to pass into gp_camera_set_single_config()

In order to change the center of the autofocus to pixel 100x100 (WIDTH x HEIGHT), I've tried the following commands, but not really getting anywhere. Didn't know if you happened to know how to pass this param?

gp_camera_set_single_config(self.camera, 'changefarea', '100x100') gp_camera_set_single_config(self.camera, '--changefarea', '100x100')

gp_camera_set_single_config(self.camera, 'changefarea', {
          "idx": "6,6,0,0",
          "ro": 0,
          "name": "changeafarea",
          "label": "Set Nikon Autofocus area",
          "type": 2,
          "typestr": "GP_WIDGET_TEXT",
          "value": "100x100"
 })
gp_camera_set_single_config(self.camera, '--changefarea', {
          "idx": "6,6,0,0",
          "ro": 0,
          "name": "changeafarea",
          "label": "Set Nikon Autofocus area",
          "type": 2,
          "typestr": "GP_WIDGET_TEXT",
          "value": "100x100"
 })
jim-easterbrook commented 2 years ago

This is a question about libgphoto2, rather than the Python interface to it, so does not belong here.

gp_camera_get_single_config returns a CameraWidget object. You modify that widget, setting the value you want, then pass it to gp_camera_set_single_config. See the libgphoto2 documentation for more details. http://www.gphoto.org/doc/api/gphoto2-camera_8h.html#ae231c37c434852418e308cda85f262e9

mexicantexan commented 2 years ago

Ah! My fault, I appreciate the guidance :) Looking at the documentation, I'm now trying the following which sets the config!! Thank you! :D

config_name =  "changeafarea"
value = "100x100"  # in my code I have it linked up to PyQt5 window where I am clicking around the live-view and the pixel value of where I clicked is being passed back and formatted into this string format

while True:
          # wait for config widget
          config_widget = gp.gp_camera_get_single_config(self.camera, config_name)
          if config_widget[1] is not None:
              break
config_widget = config_widget[1]
config_set_response = gp.gp_widget_set_value(config_widget, value)
print('set response:', gp.gp_widget_get_value(config_widget))
gp.gp_camera_set_single_config(self.camera, config_name, config_widget)

Not sure if I'm understanding "chageafarea" though... I assumed that it was the pixel location to center the AF on, but that seems to be wrong. Have you had any experience with this setting?

jim-easterbrook commented 2 years ago

No, I don't have a Nikon camera.

mexicantexan commented 2 years ago

No worries! I appreciate the help