Exemple #1
0
def setConfig(config_item, config_value):
    child_type = gp.check_result(gp.gp_widget_get_type(
        config_all[config_item]))
    if child_type == gp.GP_WIDGET_RADIO:
        value = gp.check_result(
            gp.gp_widget_get_choice(config_all[config_item],
                                    int(config_value)))
        gp.check_result(gp.gp_widget_set_value(config_all[config_item], value))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    elif child_type == gp.GP_WIDGET_TEXT:
        gp.check_result(
            gp.gp_widget_set_value(config_all[config_item], config_value))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    elif child_type == gp.GP_WIDGET_RANGE:
        gp.check_result(
            gp.gp_widget_set_value(config_all[config_item], int(config_value)))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    elif child_type == gp.GP_WIDGET_TOGGLE:
        value = gp.check_result(gp.gp_widget_get_value(
            config_all[config_item]))
        if value:
            gp.check_result(gp.gp_widget_set_value(config_all[config_item], 0))
        else:
            gp.check_result(gp.gp_widget_set_value(config_all[config_item], 1))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    return "done"
Exemple #2
0
def update_exposure_settings(camera, speed=None, fnum=None, iso=None):

    '''
    Set exposure combination.
    '''

    # get config
    config = gp.check_result(gp.gp_camera_get_config(camera))

    # update shutter speed
    if speed is not None:
        speed_cfg = gp.check_result( \
                gp.gp_widget_get_child_by_name(config, 'shutterspeed'))
        gp.check_result(gp.gp_widget_set_value(speed_cfg, speed))

    # update aperture
    if fnum is not None:
        fnum_cfg = gp.check_result( \
                gp.gp_widget_get_child_by_name(config, 'f-number'))
        gp.check_result(gp.gp_widget_set_value(fnum_cfg, fnum))

    # update iso
    if iso is not None:
        iso_cfg = gp.check_result( \
                gp.gp_widget_get_child_by_name(config, 'iso'))
        gp.check_result(gp.gp_widget_set_value(iso_cfg, iso))

    # write value.
    gp.check_result(gp.gp_camera_set_config(camera, config))
def set_camera_config(camera, exp, iso, f_val):

    if DEBUG:
        print('Getting previous camera configuration...', file=sys.stderr)
    camera_config = camera.get_config()

    error, exp_conf = gp.gp_widget_get_child_by_name(camera_config,
                                                     'shutterspeed')
    assert error == 0, "ERROR while retrieving current exposure"
    error, iso_conf = gp.gp_widget_get_child_by_name(camera_config, 'iso')
    assert error == 0, "ERROR while retrieving current ISO"
    error, f_conf = gp.gp_widget_get_child_by_name(camera_config, 'f-number')
    assert error == 0, "ERROR while retrieving current aperture"

    error = gp.check_result(gp.gp_widget_set_value(exp_conf, exp))
    assert error == 0, "ERROR while setting exposure to {}".format(exp)
    error = gp.check_result(gp.gp_widget_set_value(iso_conf, iso))
    assert error == 0, "ERROR while setting ISO to {}".format(iso)
    error = gp.check_result(gp.gp_widget_set_value(f_conf, f_val))
    assert error == 0, "ERROR while setting aperture to {}".format(f_val)

    if DEBUG:
        print("Setting new camera configuration (exp {}, iso {}, f {})...".
              format(exp, iso, f_val),
              file=sys.stderr)
    error = gp.check_result(gp.gp_camera_set_config(camera, camera_config))
    assert error == 0, "ERROR while setting camera configuration"
    if DEBUG:
        print('New camera configuration set', file=sys.stderr)
Exemple #4
0
 def configure(self):
     with open_camera() as (camera, context):
         config = gp.check_result(gp.gp_camera_get_config(camera, context))
         for param, choice in CAMERA_CONFIG.iteritems():
             widget = gp.check_result(
                 gp.gp_widget_get_child_by_name(config, param))
             value = gp.check_result(gp.gp_widget_get_choice(
                 widget, choice))
             gp.gp_widget_set_value(widget, value)
         gp.gp_camera_set_config(camera, config, context)
Exemple #5
0
 def focus_nearer(self, steps):
     with open_camera() as (camera, context):
         config = gp.check_result(gp.gp_camera_get_config(camera, context))
         widget = gp.check_result(
             gp.gp_widget_get_child_by_name(config, 'viewfinder'))
         gp.gp_widget_set_value(widget, 1)
         gp.gp_camera_set_config(camera, config, context)
         time.sleep(0.5)
         self._focus_nearer(steps, camera, config, context)
         gp.gp_widget_set_value(widget, 1)
         gp.gp_camera_set_config(camera, config, context)
def app_capture_image():
    global CAMERA

    # Handle getting the camera
    ensure_camera()
    if CAMERA == None:
        return 'The camera is not connected', 500

    # Get the config
    config = CAMERA.get_config()

    # Get the widgets
    OK, capturetarget_widget = gp.gp_widget_get_child_by_name(config, 'capturetarget')
    if OK != gp.GP_OK:
        CAMERA = None
        ensure_camera() # This will also not be okay if the camera disconnects
        return 'There are no widgets with the name of capturetarget or the camera is disconnected', 500

    OK, viewfinder_widget = gp.gp_widget_get_child_by_name(config, 'viewfinder')
    if OK != gp.GP_OK:
        CAMERA = None
        ensure_camera() # This will also not be okay if the camera disconnects
        return 'There are no widgets with the name of viewfinder or the camera is disconnected', 500

    OK, imagequality_widget = gp.gp_widget_get_child_by_name(config, 'imagequality')
    if OK != gp.GP_OK:
        CAMERA = None
        ensure_camera() # This will also not be okay if the camera disconnects
        return 'There are no widgets with the name of imagequality or the camera is disconnected', 500

    # Set the capture target to 'Memory card'
    OK = gp.gp_widget_set_value(capturetarget_widget, 'Memory card')
    if OK != gp.GP_OK:
        return 'Could not set the capture target to Memory card', 500

    # Set the view finder to 0 (in case it it 1 from the capture preview)
    OK = gp.gp_widget_set_value(viewfinder_widget, 0)
    if OK != gp.GP_OK:
        return 'Could not set the view finder to 0', 500

    # Set the image format back to 'NEF (Raw)'
    OK = gp.gp_widget_set_value(imagequality_widget, 'NEF (Raw)')
    if OK != gp.GP_OK:
        return 'Could not set the image quality to NEF (Raw)', 500

    OK = gp.gp_camera_set_config(CAMERA, config)
    if OK != gp.GP_OK:
        return 'Could not update the camera configuration', 500

    # Capture the image (to the memory card)
    CAMERA.capture(gp.GP_CAPTURE_IMAGE)

    return '', 301
 def set_datetime(config):
     OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetime')
     if OK >= gp.GP_OK:
         widget_type = gp.check_result(gp.gp_widget_get_type(date_config))
         if widget_type == gp.GP_WIDGET_DATE:
             now = int(time.time())
             gp.check_result(gp.gp_widget_set_value(date_config, now))
         else:
             now = time.strftime('%Y-%m-%d %H:%M:%S')
             gp.check_result(gp.gp_widget_set_value(date_config, now))
         return True
     return False
Exemple #8
0
 def focus(self, steps=settings.CAMERA_FOCUS_STEPS):
     with open_camera() as (camera, context):
         config = gp.check_result(gp.gp_camera_get_config(camera, context))
         widget = gp.check_result(
             gp.gp_widget_get_child_by_name(config, 'viewfinder'))
         gp.gp_widget_set_value(widget, 1)
         gp.gp_camera_set_config(camera, config, context)
         time.sleep(0.5)
         # focus is relative so we need to focus the furthest possible before adjusting
         self._focus_further(80, camera, config, context)
         self._focus_nearer(steps, camera, config, context)
         gp.gp_widget_set_value(widget, 1)
         gp.gp_camera_set_config(camera, config, context)
Exemple #9
0
 def _change_focus(self, direction, camera, config, context):
     """
     :param direction: 1 further, 0 nearer
     """
     widget = gp.check_result(
         gp.gp_widget_get_child_by_name(config, 'manualfocusdrive'))
     value = gp.check_result(
         gp.gp_widget_get_choice(widget, 6 if direction else 2))
     gp.gp_widget_set_value(widget, value)
     gp.gp_camera_set_config(camera, config, context)
     value = gp.check_result(gp.gp_widget_get_choice(widget, 3))
     gp.gp_widget_set_value(widget, value)
     gp.gp_camera_set_config(camera, config, context)
def main():
    # use Python logging
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    callback_obj = 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())
    gp.check_result(gp.gp_camera_init(camera))
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera))
    # 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))
    # clean up
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Exemple #11
0
def one_photo(camera, context, value, filename):
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # find the capture target config item
    shutterspeed = gp.check_result(
        gp.gp_widget_get_child_by_name(config, 'shutterspeed'))
    # check value in range
    count = gp.check_result(gp.gp_widget_count_choices(shutterspeed))
    if value < 0 or value >= count:
        print('Parameter out of range')
        return 1
    # set value
    speedvalue = gp.check_result(gp.gp_widget_get_choice(shutterspeed, value))

    gp.check_result(
        gp.gp_widget_set_value(shutterspeed, speedvalue)
    )  # set config gp.check_result(gp.gp_camera_set_config(camera, config, context))
    print('Capturing image (shutterspeed=%d)' % value)
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context))

    target = filename + ".jpg"

    camera_file = gp.check_result(
        gp.gp_camera_file_get(camera, file_path.folder, file_path.name,
                              gp.GP_FILE_TYPE_NORMAL, context))
    gp.check_result(gp.gp_file_save(camera_file, target))
Exemple #12
0
    def open(self):
        context = gp.Context()
        camera = gp.Camera()
        camera.init(context)

        config = camera.get_config(context)

        # find and check the image format config item
        ok, image_format = gp.gp_widget_get_child_by_name(
            config, 'imageformat')
        if ok >= gp.GP_OK:
            value = gp.check_result(gp.gp_widget_get_value(image_format))
            if value == 'raw':
                raise RuntimeError('Cannot preview raw images!')

        # find and set the capture size class config item
        # this is required for some canon cameras and does not hurt for others
        ok, capture_size_class = gp.gp_widget_get_child_by_name(
            config, 'capturesizeclass')
        if ok >= gp.GP_OK:
            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))
            gp.check_result(gp.gp_camera_set_config(camera, config, context))

        self.context = context
        self.camera = camera
        self.config = config
Exemple #13
0
 def set_config(self, config_name, value):
     self.log("Setting '{}' to '{}'".format(config_name, value))
     config, widget = self._get_widget(config_name)
     gp.check_result(gp.gp_widget_set_value(widget, value))
     gp.check_result(
             gp.gp_camera_set_config(self.camera, config, self.context))
     self.log("Set '{}' to '{}'".format(config_name, value))
Exemple #14
0
 def new_value(self):
     if sys.version_info[0] < 3:
         value = unicode(self.text()).encode('utf-8')
     else:
         value = str(self.text())
     gp.check_result(gp.gp_widget_set_value(self.config, value))
     self.config_changed()
Exemple #15
0
 def init_camera(self):
     self.log.debug("Init GPhoto2 camera")
     callback_obj = gp.check_result(gp.use_python_logging())
     self.camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(self.camera))
     # required configuration will depend on camera type!
     self.log.info('Checking camera config')
     # get configuration tree
     config = gp.check_result(gp.gp_camera_get_config(self.camera))
     # find the image format config item
     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():
             self.log.error('Cannot preview raw images')
             return None
     # 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(self.camera, config))
     return True
Exemple #16
0
    def __init__(self, resolution=(320, 240), framerate=32, **kwargs):
        print("Init camera")
        # SLR Setup
        self.shotRequested = False
        # GPhoto init / testing
        self.context = gp.gp_context_new()
        self.error, self.camera = gp.gp_camera_new()
        self.error = gp.gp_camera_init(self.camera, self.context)
        self.error, self.text = gp.gp_camera_get_summary(
            self.camera, self.context)

        # required configuration will depend on camera type!
        print('Checking camera config')
        self.config = gp.check_result(gp.gp_camera_get_config(self.camera))
        OK, image_format = gp.gp_widget_get_child_by_name(
            self.config, 'imageformat')
        if OK >= gp.GP_OK:
            value = gp.check_result(gp.gp_widget_get_value(image_format))
            if 'raw' in value.lower():
                print('Cannot preview raw images')
        # find the capture size class config item
        OK, capture_size_class = gp.gp_widget_get_child_by_name(
            self.config, 'capturesizeclass')
        if OK >= gp.GP_OK:
            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))
            gp.check_result(gp.gp_camera_set_config(self.camera, config))

        self.frame = None
        self.shot = None
        self.stopped = False
Exemple #17
0
def initCamera():
    global camera
    global context
    print("Init camera")
    # SLR Setup
    # GPhoto init / testing
    context = gp.gp_context_new()
    error, camera = gp.gp_camera_new()
    error = gp.gp_camera_init(camera, context)
    error, text = gp.gp_camera_get_summary(camera, context)
    #print('Summary')
    #print('=======')
    #print(text.text)

    # required configuration will depend on camera type!
    print('Checking camera config')
    config = gp.check_result(gp.gp_camera_get_config(camera))
    OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
    if OK >= gp.GP_OK:
        value = gp.check_result(gp.gp_widget_get_value(image_format))
        if 'raw' in value.lower():
            print('Cannot preview raw images')
    # find the capture size class config item
    OK, capture_size_class = gp.gp_widget_get_child_by_name(
        config, 'capturesizeclass')
    if OK >= gp.GP_OK:
        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))
        gp.check_result(gp.gp_camera_set_config(camera, config))
def set_datetime(config):
    OK, sync_config = gp.gp_widget_get_child_by_name(config, "syncdatetime")
    if OK >= gp.GP_OK:
        gp.check_result(gp.gp_widget_set_value(sync_config, 1))
        return True
    OK, date_config = gp.gp_widget_get_child_by_name(config, "datetime")
    if OK >= gp.GP_OK:
        widget_type = gp.check_result(gp.gp_widget_get_type(date_config))
        if widget_type == gp.GP_WIDGET_DATE:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        else:
            now = time.strftime("%Y-%m-%d %H:%M:%S")
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        return True
    return False
 def new_value(self):
     if sys.version_info[0] < 3:
         value = unicode(self.text()).encode('utf-8')
     else:
         value = str(self.text())
     gp.check_result(gp.gp_widget_set_value(self.config, value))
     self.config_changed()
def one_photo(camera, context, value, filename):
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # find the capture target config item
    shutterspeed = gp.check_result(
        gp.gp_widget_get_child_by_name(config, 'shutterspeed'))
    # check value in range
    count = gp.check_result(gp.gp_widget_count_choices(shutterspeed))
    if value < 0 or value >= count:
        print('Parameter out of range')
        return 1
    # set value
    speedvalue = gp.check_result(gp.gp_widget_get_choice(shutterspeed, value))

    gp.check_result(gp.gp_widget_set_value(shutterspeed, speedvalue)) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context))
    print('Capturing image (shutterspeed=%d)' % value)
    file_path = gp.check_result(gp.gp_camera_capture(
        camera, gp.GP_CAPTURE_IMAGE, context))

    target = filename+".jpg"

    camera_file = gp.check_result(gp.gp_camera_file_get(
            camera, file_path.folder, file_path.name,
            gp.GP_FILE_TYPE_NORMAL, context))
    gp.check_result(gp.gp_file_save(camera_file, target))
def connect_camera():
  global CAMERA

  logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
  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
  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():
          raise PeripheralStatusError('Camera is setup to record raw, but we need previs, and preview does not work with raw images')
  # 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))
Exemple #22
0
def focus(closer=True, small_step=False,
          custom=None, debug=False):
    config = camera.get_config()
    param = 'manualfocusdrive'
    if small_step:
        choice = near_small_step if closer else far_small_step
    else:    
        choice = near if closer else far
    if custom:
        choice = custom
    widget = gp.check_result(gp.gp_widget_get_child_by_name(config, param))
    value = gp.check_result(gp.gp_widget_get_choice(widget, choice))
    if debug:
        print("value: {}".format(value), file=sys.stderr)
    gp.gp_widget_set_value(widget, value)
    return gp.gp_camera_set_config(camera, config, context)
Exemple #23
0
def main():
    # use Python logging
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    callback_obj = 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())
    gp.check_result(gp.gp_camera_init(camera))
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera))
    # 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))
    # clean up
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
def set_config_item(name):
    global CAMERA

    # Handle getting the camera
    ensure_camera()
    if CAMERA == None:
        return 'The camera is not connected', 500

    value = request.data.decode('UTF-8')

    # Get the config
    config = CAMERA.get_config()

    # Get the widget
    OK, widget = gp.gp_widget_get_child_by_name(config, name)
    if OK != gp.GP_OK:
        CAMERA = None
        ensure_camera() # This will also not be okay if the camera disconnects
        return 'There are no widgets with the name of ' + name, 500

    OK = gp.gp_widget_set_value(widget, value)
    if OK != gp.GP_OK:
        return 'Could not set the value', 500

    OK = gp.gp_camera_set_config(CAMERA, config)
    if OK != gp.GP_OK:
        return 'Could not set the config', 500

    return 'Value updated successfully'
Exemple #25
0
def setPropertyTo(camera, parameter, index):
    config = getConfigurationOf(camera)
    capture_target = gp.check_result(
        gp.gp_widget_get_child_by_name(config, parameter))
    value = gp.check_result(gp.gp_widget_get_choice(capture_target, index))
    gp.check_result(gp.gp_widget_set_value(capture_target, value))
    gp.check_result(gp.gp_camera_set_config(camera, config))
    return
 def my_set(name, value):
     OK, widget = gp.gp_widget_get_child_by_name(config, name)
     if OK >= gp.GP_OK:
         widget_type = gp.check_result(gp.gp_widget_get_type(widget))
         gp.check_result(gp.gp_widget_set_value(widget, value))
         gp.check_result(gp.gp_camera_set_config(camera, config))
     else:
         print("Error setting value %s for %s using widget %s" % (value, name, widget))
def set_config_value (camera, config, context, config_name, value):
    OK, config_child = gp.gp_widget_get_child_by_name(config,config_name)
    if OK >= gp.GP_OK:
        gp.check_result(gp.gp_widget_set_value(config_child, value))
        gp.check_result(gp.gp_camera_set_config(camera, config, context))

        return True
    else:
        return False
Exemple #28
0
    def _set_config_value_checked(self, name, value):
        value = str(value)
        ret = False
        for t in range(0, 20):
            try:
                config = gp.check_result(
                    gp.gp_camera_get_config(self.camera, self.context))
                OK, widget = gp.gp_widget_get_child_by_name(config, name)

                if OK >= gp.GP_OK:
                    num = None
                    choice_count = gp.check_result(
                        gp.gp_widget_count_choices(widget))
                    logging.info("count %d", choice_count)
                    for i in range(choice_count):
                        vi = gp.check_result(gp.gp_widget_get_choice(
                            widget, i))
                        if vi.lower() == value.lower():
                            num = i
                            value = vi
                            break
                        try:
                            if abs(float(vi) - float(value)) < 0.000001:
                                value = vi
                                num = i
                                break
                        except ValueError:
                            pass
                        try:
                            if '/' in vi:
                                fr = vi.split('/')
                                fr = float(fr[0]) / float(fr[1])
                                if abs(fr - float(value)) < abs(fr * 0.001):
                                    value = vi
                                    num = i
                                    break
                        except:
                            pass

                    if num is not None:
                        logging.info("set %s => %s (choice %d)" %
                                     (name, value, num))
                        # set value
                        gp.check_result(gp.gp_widget_set_value(widget, value))
                        ret = True
                    else:
                        logging.info("cant't set %s => %s" % (name, value))
                # set config
                gp.check_result(
                    gp.gp_camera_set_config(self.camera, config, self.context))
                break
            except gp.GPhoto2Error as ex:
                logging.exception('failed')
                time.sleep(0.1)
                ret = False
                continue
            return ret
Exemple #29
0
    def _set_config_value(self, config, name, value):

        error, window = gp.gp_widget_get_child_by_name(config, name)
        gp.check_result(error)

        error = gp.gp_widget_set_value(window, value)
        gp.check_result(error)

        error = gp.gp_camera_set_config(self.camera, config)
        gp.check_result(error)
Exemple #30
0
 def set_capture_target(self, value):
     config = gp.check_result(gp.gp_camera_get_config(self.camera))
     capture_target = gp.check_result(
         gp.gp_widget_get_child_by_name(config, 'capturetarget'))
     count = gp.check_result(gp.gp_widget_count_choices(capture_target))
     if value < 0 or value >= count:
         print('Parameter out of range')
         value = 1
     value = gp.check_result(gp.gp_widget_get_choice(capture_target, value))
     gp.check_result(gp.gp_widget_set_value(capture_target, value))
     gp.check_result(gp.gp_camera_set_config(self.camera, config))
     gp.check_result(gp.gp_camera_exit(self.camera))
def set_datetime(config, model):
    if model == 'Canon EOS 100D':
        OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetimeutc')
        if OK >= gp.GP_OK:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
            return True
    OK, sync_config = gp.gp_widget_get_child_by_name(config, 'syncdatetime')
    if OK >= gp.GP_OK:
        gp.check_result(gp.gp_widget_set_value(sync_config, 1))
        return True
    OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetime')
    if OK >= gp.GP_OK:
        widget_type = gp.check_result(gp.gp_widget_get_type(date_config))
        if widget_type == gp.GP_WIDGET_DATE:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        else:
            now = time.strftime('%Y-%m-%d %H:%M:%S')
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        return True
    return False
Exemple #32
0
def set_datetime(config, model):
    if model == 'Canon EOS 100D':
        OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetimeutc')
        if OK >= gp.GP_OK:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
            return True
    OK, sync_config = gp.gp_widget_get_child_by_name(config, 'syncdatetime')
    if OK >= gp.GP_OK:
        gp.check_result(gp.gp_widget_set_value(sync_config, 1))
        return True
    OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetime')
    if OK >= gp.GP_OK:
        widget_type = gp.check_result(gp.gp_widget_get_type(date_config))
        if widget_type == gp.GP_WIDGET_DATE:
            now = int(time.time())
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        else:
            now = time.strftime('%Y-%m-%d %H:%M:%S')
            gp.check_result(gp.gp_widget_set_value(date_config, now))
        return True
    return False
Exemple #33
0
def main():
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.ERROR)
    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
    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')

    for x in xrange(1,100):
        millis = int(round(time.time() * 1000))

        camera_file = gp.check_result(gp.gp_camera_capture_preview(camera))

        print("capture %d %s\n" % (int(round(time.time() * 1000)) - millis, camera_file))

        file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))

        print("download %d\n" % (int(round(time.time() * 1000)) - millis))

        data = memoryview(file_data)

    # display image
    #image = Image.open(io.BytesIO(file_data))
    #image.show()
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Exemple #34
0
 def set_parameter(self, parameter_name, set_value):
     error, parameter = gphoto2.gp_widget_get_child_by_name(self.config, parameter_name)
     if error < 0:
         print "Parameter does not exist"
         return
     if parameter_name != 'bulb' and parameter_name != 'capture':
         error, value = gphoto2.gp_widget_get_choice(parameter, set_value)
     else:
         error = 0
         value = set_value
     if error < 0:
         print "Value out of range"
         return
     error = gphoto2.gp_widget_set_value(parameter, value)
     error = gphoto2.gp_camera_set_config(self.camera, self.config, self.context)
Exemple #35
0
    def getPicture(self):
        #restore the original shutterspeed changed in getPreview
        if (self.BrightPreview):
            config = self._cap.get_config()
            shutterspeed = gp.check_result(
                gp.gp_widget_get_child_by_name(config, 'shutterspeed'))
            gp.check_result(gp.gp_widget_set_value(shutterspeed,
                                                   self._shutter))
            gp.check_result(gp.gp_camera_set_config(self._cap, config))
            self.FirstPreview = True

        file_path = self._cap.capture(gp.GP_CAPTURE_IMAGE)
        camera_file = self._cap.file_get(file_path.folder, file_path.name,
                                         gp.GP_FILE_TYPE_NORMAL)
        file_data = camera_file.get_data_and_size()
        return Image.open(io.BytesIO(file_data))
Exemple #36
0
	def set_config_value(self, name, value):
		for t in range(0, 20):
			try:
				config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context))
				OK, widget = gp.gp_widget_get_child_by_name(config, name)
				if OK >= gp.GP_OK:
					print "set %s => %s" % (name, value)
					# set value
					gp.check_result(gp.gp_widget_set_value(widget, value))
				# set config
				gp.check_result(gp.gp_camera_set_config(self.camera, config, self.context))
				break
			except gp.GPhoto2Error as ex:
				print ex.code
				time.sleep(0.1)
				continue
Exemple #37
0
def set_capture_target(camera, value:int):
    config = gp.check_result(gp.gp_camera_get_config(camera))
    # 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))
    # clean up
    # gp.check_result(gp.gp_camera_exit(camera))
    return 0
Exemple #38
0
def take_a_pic():
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    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
    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')
                camera_file = gp.check_result(
                    gp.gp_camera_capture_preview(camera))
                file_data = gp.check_result(
                    gp.gp_file_get_data_and_size(camera_file))
                # display image
                data = memoryview(file_data)
                print(type(data), len(data))
                print(data[:10].tolist())
                image = Image.open(io.BytesIO(file_data))
                image.show()
                gp.check_result(gp.gp_camera_exit(camera))
                return image
Exemple #39
0
 def __apply_settings(self, settings):
     """
     takes dict of keys as option names and the corresponding values
     """
     print '__apply_settings'
     for key, value in settings.items():
         if key not in self.__config_dict:
             print 'camera: can not set %s '%(key,value)
             continue
         widget = self.__config_dict[key].get('_widget')
         if not widget:
             print 'camera: can not set %s '%(key,value)
             continue
         print key, value
         gp.check_result(gp.gp_widget_set_value(widget, value))
         self.__config_dict[key]['_value']=value
     gp.check_result(gp.gp_camera_set_config(
         self.__camera, self.__config, self.__context))
Exemple #40
0
def set_config_value(camera, field_name, field_value):
    """
    Set configValue for given configField
    :param field_name:
    :param field_value:
    :return:
    """
    # get configuration tree
    config = camera.get_config()
#    for child in config.get_children():
#        label = '{} ({})'.format(child.get_label(), child.get_name())
#        print(label)
    # find the capture target config item
    config_target = gp.check_result(gp.gp_widget_get_child_by_name(config, str(field_name)))
    # value = gp.check_result(gp.gp_widget_get_choice(config_target, 2))
    gp.check_result(gp.gp_widget_set_value(config_target, str(field_value)))
    # set config
    camera.set_config(config)
 def set_config_value(self, field_name, field_value):
     """
     Set configValue for given configField
     :param field_name:
     :param field_value:
     :return:
     """
     try:
         # get configuration tree
         config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context))
         # find the capture target config item
         config_target = gp.check_result(gp.gp_widget_get_child_by_name(config, str(field_name)))
         # value = gp.check_result(gp.gp_widget_get_choice(config_target, 2))
         gp.check_result(gp.gp_widget_set_value(config_target, str(field_value)))
         # set config
         gp.check_result(gp.gp_camera_set_config(self.camera, config, self.context))
         logger.debug("set field_name:{}, field_value:{}".format(field_name, field_value))
     except Exception as e:
         logger.debug(e.message)
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    context = gp.gp_context_new()
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera, context))
    # required configuration will depend on camera type!
    print('Checking camera config')
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # find the image format config item
    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, context))
    # capture preview image (not saved to camera memory card)
    print('Capturing preview image')
    camera_file = gp.check_result(gp.gp_camera_capture_preview(camera, context))
    file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
    # display image
    data = memoryview(file_data)
    print(type(data), len(data))
    print(data[:10].tolist())
    image = Image.open(io.BytesIO(file_data))
    image.show()
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Exemple #43
0
	def set_config_value_checked(self, name, value):
		value = str(value)
		ret = False
		for t in range(0, 20):
			try:
				config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context))
				OK, widget = gp.gp_widget_get_child_by_name(config, name)
				
				if OK >= gp.GP_OK:
					num = None
					choice_count = gp.check_result(gp.gp_widget_count_choices(widget))
					print "count", choice_count
					for i in range(choice_count):
						vi = gp.check_result(gp.gp_widget_get_choice(widget, i))
						if vi.lower() == value.lower():
							num = i
							value = vi
							break
						try:
							if abs(float(vi) - float(value)) < 0.000001:
								value = vi
								num = i
								break
						except ValueError:
							pass
					
					if num is not None:
						print "set %s => %s (choice %d)" % (name, value, num)
						# set value
						gp.check_result(gp.gp_widget_set_value(widget, value))
						ret = True
					else:
						print "cant't set %s => %s" % (name, value)
				# set config
				gp.check_result(gp.gp_camera_set_config(self.camera, config, self.context))
				break
			except gp.GPhoto2Error as ex:
				print ex.code
				time.sleep(0.1)
				ret = False
				continue
		return ret
Exemple #44
0
def waitForCamera(context):
  showText(AREA_PREVIEW,"Warte auf Kamera ")
  pygame.display.flip()
  camera = gp.check_result(gp.gp_camera_new())
  err=gp.gp_camera_init(camera, context)
  if (err < gp.GP_OK):
    if err != gp.GP_ERROR_MODEL_NOT_FOUND:
        # some other error we can't handle here
        raise gp.GPhoto2Error(err)
    return
  # required configuration will depend on camera type!
  print('Checking camera config')
  # get configuration tree
  config = gp.check_result(gp.gp_camera_get_config(camera, context))
  # find the image format config item
  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():
          raise gp.GPhoto2Error('Cannot preview raw images')
  # 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, context))
  OK,txt=gp.gp_camera_get_summary(camera,context)
  infod=txToDict(txt.text)
  showText(AREA_PREVIEW,infod.get('Model'))
  info.camera=infod.get('Model')
  pygame.display.flip()
  return camera
Exemple #45
0
def set_config_value(key, value, camera, context):
    config_widget = gp.check_result(gp.gp_camera_get_config(camera, context))
    camera_widget_child = gp.check_result(gp.gp_widget_get_child_by_name(config_widget, key))
    gp.check_result(gp.gp_widget_set_value(camera_widget_child, value))
    gp.check_result(gp.gp_camera_set_config(camera, config_widget, context))
 def new_value(self, value):
     value = value.toPyDateTime() - datetime.fromtimestamp(0)
     value = int(value.total_seconds())
     gp.check_result(gp.gp_widget_set_value(self.config, value))
     self.config_changed()
 def new_value(self, value):
     value = str(self.itemText(value))
     gp.check_result(gp.gp_widget_set_value(self.config, value))
     self.config_changed()
 def new_value(self):
     for button, choice in self.buttons:
         if button.isChecked():
             gp.check_result(gp.gp_widget_set_value(self.config, choice))
             self.config_changed()
             return
 def new_value(self):
     value = self.isChecked()
     gp.check_result(gp.gp_widget_set_value(self.config, (0, 1)[value]))
     self.config_changed()
 def new_value(self):
     value = float(self.value()) * self.inc
     gp.check_result(gp.gp_widget_set_value(self.config, value))
     self.config_changed()