-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples to get/set capture target
This was requested in issue #10. Note that not all cameras support setting the capture target.
- Loading branch information
1 parent
aac2f36
commit 5632fcc
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
|
||
# python-gphoto2 - Python interface to libgphoto2 | ||
# http://github.com/jim-easterbrook/python-gphoto2 | ||
# Copyright (C) 2014 Jim Easterbrook jim@jim-easterbrook.me.uk | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from __future__ import print_function | ||
|
||
import logging | ||
import sys | ||
|
||
import gphoto2 as gp | ||
|
||
def main(): | ||
# use Python logging | ||
logging.basicConfig( | ||
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) | ||
gp.check_result(gp.use_python_logging()) | ||
# open camera connection | ||
camera = gp.check_result(gp.gp_camera_new()) | ||
context = gp.gp_context_new() | ||
gp.check_result(gp.gp_camera_init(camera, context)) | ||
# get configuration tree | ||
config = gp.check_result(gp.gp_camera_get_config(camera, context)) | ||
# find the capture target config item | ||
capture_target = gp.check_result( | ||
gp.gp_widget_get_child_by_name(config, 'capturetarget')) | ||
# print current setting | ||
value = gp.check_result(gp.gp_widget_get_value(capture_target)) | ||
print('Current setting:', value) | ||
# print possible settings | ||
for n in range(gp.check_result(gp.gp_widget_count_choices(capture_target))): | ||
choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n)) | ||
print('Choice:', n, choice) | ||
# clean up | ||
gp.check_result(gp.gp_camera_exit(camera, context)) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python | ||
|
||
# python-gphoto2 - Python interface to libgphoto2 | ||
# http://github.com/jim-easterbrook/python-gphoto2 | ||
# Copyright (C) 2014 Jim Easterbrook jim@jim-easterbrook.me.uk | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from __future__ import print_function | ||
|
||
import logging | ||
import sys | ||
|
||
import gphoto2 as gp | ||
|
||
def main(): | ||
# use Python logging | ||
logging.basicConfig( | ||
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) | ||
gp.check_result(gp.use_python_logging()) | ||
# get user value | ||
if len(sys.argv) != 2: | ||
print('One command line parameter required') | ||
return 1 | ||
try: | ||
value = int(sys.argv[1]) | ||
except: | ||
print('Integer parameter required') | ||
return 1 | ||
# open camera connection | ||
camera = gp.check_result(gp.gp_camera_new()) | ||
context = gp.gp_context_new() | ||
gp.check_result(gp.gp_camera_init(camera, context)) | ||
# get configuration tree | ||
config = gp.check_result(gp.gp_camera_get_config(camera, context)) | ||
# find the capture target config item | ||
capture_target = gp.check_result( | ||
gp.gp_widget_get_child_by_name(config, 'capturetarget')) | ||
# check value in range | ||
count = gp.check_result(gp.gp_widget_count_choices(capture_target)) | ||
if value < 0 or value >= count: | ||
print('Parameter out of range') | ||
return 1 | ||
# set value | ||
value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) | ||
gp.check_result(gp.gp_widget_set_value(capture_target, value)) | ||
# set config | ||
gp.check_result(gp.gp_camera_set_config(camera, config, context)) | ||
# clean up | ||
gp.check_result(gp.gp_camera_exit(camera, context)) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |