Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
camera = gp.Camera()
context = gp.gp_context_new()
camera.init(context)
config = camera.get_config(context)
# find the date/time setting config item and get it
# name varies with camera driver
# Canon EOS350d - 'datetime'
# PTP - 'd034'
for name, fmt in (('datetime', '%Y-%m-%d %H:%M:%S'),
('d034', None)):
OK, datetime_config = gp.gp_widget_get_child_by_name(config, name)
if OK >= gp.GP_OK:
widget_type = gp.check_result(gp.gp_widget_get_type(datetime_config))
if widget_type == gp.GP_WIDGET_DATE:
raw_value = gp.check_result(
gp.gp_widget_get_value(datetime_config))
camera_time = datetime.fromtimestamp(raw_value)
else:
raw_value = gp.check_result(
gp.gp_widget_get_value(datetime_config))
if fmt:
camera_time = datetime.strptime(raw_value, fmt)
else:
camera_time = datetime.utcfromtimestamp(float(raw_value))
break
imgfmtselected, imgfmtoptions = readRange (camera, context, 'imgsettings', 'imageformat')
wbselected, wboptions = readRange (camera, context, 'imgsettings', 'whitebalance')
isoselected, isooptions = readRange (camera, context, 'imgsettings', 'iso')
apselected, apoptions = readRange (camera, context, 'capturesettings', 'aperture')
shutselected, shutoptions = readRange (camera, context, 'capturesettings', 'shutterspeed')
expselected, expoptions = readRange (camera, context, 'capturesettings', 'exposurecompensation')
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
# required configuration will depend on camera type!
print('Checking camera config')
# get configuration tree
config = gp.check_result(gp.gp_camera_get_config(camera))
# find the image format config item
# camera dependent - 'imageformat' is 'imagequality' on some
OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
if OK >= gp.GP_OK:
# get current setting
value = gp.check_result(gp.gp_widget_get_value(image_format))
# make sure it's not raw
if 'raw' in value.lower():
print('Cannot preview raw images')
return 1
# find the capture size class config item
# need to set this on my Canon 350d to get preview to work at all
OK, capture_size_class = gp.gp_widget_get_child_by_name(
config, 'capturesizeclass')
if OK >= gp.GP_OK:
# set value
value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2))
gp.check_result(gp.gp_widget_set_value(capture_size_class, value))
# set config
gp.check_result(gp.gp_camera_set_config(camera, config))
# capture preview image (not saved to camera memory card)
print('Capturing preview image')
def getPreviewImage(camera, context, config):
""" Straight out of Jim's examples """
OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
if OK >= gp.GP_OK:
# get current setting
value = gp.check_result(gp.gp_widget_get_value(image_format))
# make sure it's not raw
if 'raw' in value.lower():
app.logger.debug('Cannot preview raw images')
return 1
# find the capture size class config item
# need to set this on my Canon 350d to get preview to work at all
OK, capture_size_class = gp.gp_widget_get_child_by_name(
config, 'capturesizeclass')
if OK >= gp.GP_OK:
# set value
value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2))
gp.check_result(gp.gp_widget_set_value(capture_size_class, value))
# set config
gp.check_result(gp.gp_camera_set_config(camera, config))
# capture preview image (not saved to camera memory card)
app.logger.debug('Capturing preview image')
def readValue ( camera, attribute ):
""" Reads a simple attribute in the camera and returns the value """
try:
object = gp.check_result(gp.gp_widget_get_child_by_name(camera, attribute))
value = gp.check_result(gp.gp_widget_get_value(object))
except:
value = ''
return value
def readValue ( camera, attribute ):
""" Reads a simple attribute in the camera and returns the value """
try:
object = gp.check_result(gp.gp_widget_get_child_by_name(camera, attribute))
value = gp.check_result(gp.gp_widget_get_value(object))
except:
value = ''
return value
def getPreviewImage(camera, context, config):
""" Straight out of Jim's examples """
OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
if OK >= gp.GP_OK:
# get current setting
value = gp.check_result(gp.gp_widget_get_value(image_format))
# make sure it's not raw
if 'raw' in value.lower():
app.logger.debug('Cannot preview raw images')
return 1
# find the capture size class config item
# need to set this on my Canon 350d to get preview to work at all
OK, capture_size_class = gp.gp_widget_get_child_by_name(
config, 'capturesizeclass')
if OK >= gp.GP_OK:
# set value
value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2))
gp.check_result(gp.gp_widget_set_value(capture_size_class, value))
# set config
gp.check_result(gp.gp_camera_set_config(camera, config))
# capture preview image (not saved to camera memory card)
app.logger.debug('Capturing preview image')