Example #1
0
def main():
    # set up our camera.
    camera, context = setup()
    # grab a single test image.
    capture_image(camera, context, "crap.jpg")
    # Get the configuration of the camera
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # Pythonify and print the configuration of the camera so
    # we can see what parameters we can play with.
    pconfig = recurse_config(config)
    print_config_dict(pconfig)
    # Put the camera in AV mode, or aperture priority.
    # Camera needs this to fiddle with aperture.
    set_config(camera, context, config,
               ["capturesettings", "autoexposuremode"], "AV")
    count = 0
    # for all of the available aperture settings...
    for param in pconfig["capturesettings"]["aperture"]:
        # get the camera configuration
        config = gp.check_result(gp.gp_camera_get_config(camera, context))
        # set the new configuration
        set_config(camera, context, config, ["capturesettings", "aperture"],
                   param)
        # and capture an image.
        fname = "Capture{:0>5}.jpg".format(count)
        capture_image(camera, context, fname)
        count += 1
Example #2
0
def main():
    # set up our camera.
    camera, context = setup()
    # grab a single test image.
    capture_image(camera, context, "crap.jpg")
    # Get the configuration of the camera
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # Pythonify and print the configuration of the camera so
    # we can see what parameters we can play with.
    pconfig = recurse_config(config)
    print_config_dict(pconfig)
    # Put the camera in AV mode, or aperture priority.
    # Camera needs this to fiddle with aperture.
    set_config(camera, context, config, ["capturesettings", "autoexposuremode"], "AV")
    count = 0
    # for all of the available aperture settings...
    for param in pconfig["capturesettings"]["aperture"]:
        # get the camera configuration
        config = gp.check_result(gp.gp_camera_get_config(camera, context))
        # set the new configuration
        set_config(camera, context, config, ["capturesettings", "aperture"], param)
        # and capture an image.
        fname = "Capture{:0>5}.jpg".format(count)
        capture_image(camera, context, fname)
        count += 1
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))
Example #4
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))
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 __init__(self):
        print "init AstroCamCanon"

        gp.check_result(gp.use_python_logging())
        self.context = gp.gp_context_new()
        self.camera = gp.check_result(gp.gp_camera_new())
        print "config"
        camera_config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context))
        child_count = gp.check_result(gp.gp_widget_count_children(camera_config))
        
        print child_count
        for n in range(child_count):
            try:
                print "============"
                child = gp.check_result(gp.gp_widget_get_child(camera_config, n))
                name = gp.check_result(gp.gp_widget_get_name(child))
                print name
                chtype = gp.check_result(gp.gp_widget_get_type(child))
                print chtype
                ro = gp.check_result(gp.gp_widget_get_readonly(child))
                print ro
                cdildcen = gp.check_result(gp.gp_widget_count_children(child))
                print cdildcen
                

            except Exception, e:
                print e
Example #7
0
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
Example #8
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
Example #9
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 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))
Example #11
0
 def change_iso_setting(self):
     camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(camera))
     camera_config = gp.check_result(gp.gp_camera_get_config(camera))
     for child in gp.check_result(gp.gp_widget_get_children(camera_config)):
         print(gp.check_result(gp.gp_widget_get_label(child)))
     gp.check_result(gp.gp_camera_exit(camera))
Example #12
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))
Example #13
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
Example #14
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
Example #15
0
    def synchronize_camera_timestamp(self):
        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

        # get configuration tree
        config = gp.check_result(gp.gp_camera_get_config(
            self.camera))  #, self.context))
        # find the date/time setting config item and set it
        if set_datetime(config):
            # apply the changed config
            gp.check_result(gp.gp_camera_set_config(self.camera,
                                                    config))  #, self.context))
        else:
            print('Could not set date & time')
        # clean up
        gp.check_result(gp.gp_camera_exit(self.camera))  #, self.context))
        return 0
Example #16
0
	def get_config_value(self, name):
		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:
			# set value
			value = gp.check_result(gp.gp_widget_get_value(widget))
			print "get %s => %s" % (name, value)
			return value
Example #17
0
    def get_config(self):
        error, config = gp.gp_camera_get_config(self.camera,self.context)
        if error != 0:
            print('init scanner: cannot get camera config!')
        else:
            self.config = config

        return error
Example #18
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
Example #19
0
    def set_autofocus(self, enabled):

        value = "Manual"
        if enabled:
            value = "Automatic"

        error, config = gp.gp_camera_get_config(self.camera)
        gp.check_result(error)

        self._set_config_value(config, "focusmode", value)
Example #20
0
    def run_autofocus(self, active):

        value = 0
        if active:
            value = 1

        error, config = gp.gp_camera_get_config(self.camera)
        gp.check_result(error)

        self._set_config_value(self.camera, config, "autofocus", value)
Example #21
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)
Example #22
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)
Example #23
0
def test_camera():
    global camera, context, config, camera_config_name, camera_config
    print("Testing Camera")
    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_list = []
    for name, addr in context.camera_autodetect():
        camera_list.append((name, addr))
    if not camera_list:
        print('No camera detected')
        return 1
    camera_list.sort(key=lambda x: x[0])
    name, addr = camera_list[0]
    camera = gp.Camera()
    #camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera, context))
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    text = gp.check_result(gp.gp_camera_get_summary(camera, context))
    print('Summary')
    print('=======')
    print(text.text)
    print('Abilities')
    print('=========')
    abilities = gp.check_result(gp.gp_camera_get_abilities(camera))
    print('model:', abilities.model)
    print('status:', abilities.status)
    print('port:', abilities.port)
    print('speed:', abilities.speed)
    print('operations:', abilities.operations)
    print('file_operations:', abilities.file_operations)
    print('folder_operations:', abilities.folder_operations)
    print('usb_vendor:', abilities.usb_vendor)
    print('usb_product:', abilities.usb_product)
    print('usb_class:', abilities.usb_class)
    print('usb_subclass:', abilities.usb_subclass)
    print('usb_protocol:', abilities.usb_protocol)
    print('library:', abilities.library)
    print('id:', abilities.id)
    print('device_type:', abilities.device_type)
    child_count = gp.check_result(gp.gp_widget_count_children(config))
    if child_count < 1:
        return
    tabs = None
    for n in range(child_count):
        child = gp.check_result(gp.gp_widget_get_child(config, n))
        camera_config.append(getConfig(child))
        label = gp.check_result(gp.gp_widget_get_label(child))
        camera_config_name.append(label)
        print('!!!!!!! CONFIG ', child, label)
    name = gp.check_result(gp.gp_widget_get_name(child))
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Example #24
0
 def initialise(self):
     # get camera config tree
     self.camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(self.camera))
     self.camera_config = gp.check_result(
         gp.gp_camera_get_config(self.camera))
     # create corresponding tree of tab widgets
     self.setWindowTitle(
         gp.check_result(gp.gp_widget_get_label(self.camera_config)))
     self.centralWidget().layout().addWidget(
         SectionWidget(self.config_changed, self.camera_config), 0, 0, 1, 3)
 def initialise(self):
     # get camera config tree
     self.camera = gp.check_result(gp.gp_camera_new())
     self.context = gp.gp_context_new()
     gp.check_result(gp.gp_camera_init(self.camera, self.context))
     self.camera_config = gp.check_result(
         gp.gp_camera_get_config(self.camera, self.context))
     # create corresponding tree of tab widgets
     self.setWindowTitle(
         gp.check_result(gp.gp_widget_get_label(self.camera_config)))
     self.centralWidget().layout().addWidget(SectionWidget(
         self.config_changed, self.camera_config), 0, 0, 1, 3)
Example #26
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))
Example #27
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)
 def get_config_value(self, field_name):
     """
     Get configValue for given configField
     :param field_name:
     :return:
     """
     # 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)))
     # check value in range
     value = gp.check_result(gp.gp_widget_get_value(config_target))
     return value
Example #29
0
    def list_config(self):

        error, config = gp.gp_camera_get_config(self, camera)
        gp.check_result(error)

        error, config_list = gp.gp_camera_list_config(self, camera, context)
        gp.check_result(error)

        for item in config_list:
            try:
                print("{0:25s} | {1}".format(item[0], _get_config_value(config, str(item[0]))))

            except gp.GPhoto2Error as e:
                print(e)
 def initialise(self):
     # get camera config tree
     self.camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(self.camera))
     self.camera_config = gp.check_result(
         gp.gp_camera_get_config(self.camera))
     # create corresponding tree of tab widgets
     self.setWindowTitle(
         gp.check_result(gp.gp_widget_get_label(self.camera_config)))
     top_widget = SectionWidget(self.config_changed, self.camera_config)
     scroll_area = QtWidgets.QScrollArea()
     scroll_area.setWidget(top_widget)
     scroll_area.setWidgetResizable(True)
     self.centralWidget().layout().addWidget(scroll_area, 0, 0, 1, 3)
Example #31
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
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 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)):
        now = datetime.now()
        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))
            print('Camera clock:  ', camera_time.isoformat(' '))
            print('Computer clock:', now.isoformat(' '))
            err = now - camera_time
            if err.days < 0:
                err = -err
                lead_lag = 'ahead'
                print('Camera clock is ahead by',)
            else:
                lead_lag = 'behind'
            print('Camera clock is %s by %d days and %d seconds' % (
                lead_lag, err.days, err.seconds))
            break
    else:
        print('Unknown date/time config item')
    # clean up
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Example #33
0
 def get_config_value(self, field_name):
     """
     Get configValue for given configField
     :param field_name:
     :return:
     """
     # 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)))
     # check value in range
     value = gp.check_result(gp.gp_widget_get_value(config_target))
     return value
Example #34
0
 def __init_camera(self):
     error, self.__camera = gp.gp_camera_new()
     self.__context = gp.gp_context_new()
     error = gp.gp_camera_init(self.__camera, self.__context)
     error, text = gp.gp_camera_get_summary(self.__camera, self.__context)
     #print('Summary')
     #('=======')
     #print(text.text)
     self.__config = gp.check_result(gp.gp_camera_get_config(self.__camera, self.__context))
     self.__config_dict = OrderedDict()
     self.__walk_config(self.__config,self.__config_dict)
     self.print_settings()
     self.__watcher = QtCore.QFileSystemWatcher([self.__cfg_file_path], self)
     self.__watcher.fileChanged.connect(self.load_settings)
     self.load_settings(self.__cfg_file_path)
Example #35
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
Example #36
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
Example #37
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
Example #38
0
def checkBattery(camera, batt_lvl):
    #global camera, batt_lvl

    # Get configuration tree
    cameraConfig = gp.check_result(gp.gp_camera_get_config(camera))
    # Get Camera model
    batteryLevelWidget = gp.check_result(
        gp.gp_widget_get_child_by_name(cameraConfig, 'batterylevel'))
    batteryLevel = ""
    batteryLevel = gp.check_result(
        gp.gp_widget_get_value(batteryLevelWidget))  #, cameraName))

    if batteryLevel < batt_lvl:
        logging.critical("Battery level too low : %d%" % int(batteryLevel))
        return False
    else:
        logging.info("Battery level : %d%" % int(batteryLevel))
        return True
def main():
    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
Example #40
0
def getCamera(cameraNumber=0):
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    # make a list of all available cameras
    camera_list = []
    for name, addr in gp.check_result(gp.gp_camera_autodetect()):
        camera_list.append((name, addr))
    camera_list.sort(key=lambda x: x[0])

    if len(camera_list) == 0:
        print("No cameras found")
        return None

    if cameraNumber < 0 or cameraNumber >= len(camera_list):
        print('Camera out of range')
        return None
    # initialise chosen camera
    name, addr = camera_list[cameraNumber]
    camera = gp.Camera()
    # search ports for camera port name
    port_info_list = gp.PortInfoList()
    port_info_list.load()
    idx = port_info_list.lookup_path(addr)
    camera.set_port_info(port_info_list[idx])
    camera.init()

    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))

    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))
    return camera
Example #41
0
def take_picture(imagedir):
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    config = gp.check_result(gp.gp_camera_get_config(camera))
    capture_target = gp.check_result(
        gp.gp_widget_get_child_by_name(config, 'capturetarget'))
    value = gp.check_result(gp.gp_widget_get_choice(capture_target, 1))
    gp.check_result(gp.gp_widget_set_value(capture_target, value))
    gp.check_result(gp.gp_camera_set_config(camera, config))
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
    file_name = datetime.now().strftime('%y%m%d-%H%M%S-%f') + file_path.name
    target = join(imagedir, file_name)
    camera_file = gp.check_result(
        gp.gp_camera_file_get(camera, file_path.folder, file_path.name,
                              gp.GP_FILE_TYPE_NORMAL))
    gp.check_result(gp.gp_file_save(camera_file, target))
    gp.check_result(gp.gp_camera_exit(camera))
    return file_name
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 date/time setting config item and set it
    if set_datetime(config):
        # apply the changed config
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    else:
        print("Could not set date & time")
    # clean up
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
 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)
Example #44
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
Example #45
0
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
Example #46
0
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 date/time setting config item and set it
    if set_datetime(config):
        # apply the changed config
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    else:
        print('Could not set date & time')
    # clean up
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Example #47
0
    def initCamera(self):
        self.context = gphoto2.gp_context_new()
        error, self.camera = gphoto2.gp_camera_new()
        error = gphoto2.gp_camera_init(self.camera, self.context)
        if error != 0:
           print "Init error!"
           quit()
        self.camera_name = self.context.camera_autodetect()[0][0]

        error, self.config = gphoto2.gp_camera_get_config(self.camera, self.context)
        self.set_parameter('imageformat', 7) # 0 to 7
        self.set_parameter('iso', 0) # 0 to 5
        self.set_parameter('whitebalance', 7) # 0 to 7
        self.set_parameter('whitebalanceadjusta', 0) # 0 to 18
        self.set_parameter('whitebalanceadjustb', 0) # 0 to 18
        self.set_parameter('shutterspeed', 0) # 0 to 52
        self.set_parameter('picturestyle', 0) # 0 to 8
        self.set_parameter('drivemode', 0) # 0 to 4
        self.set_parameter('autoexposuremode', 3) # 0 to 15
        self.set_parameter('colorspace', 0) # 0 to 1
        self.set_parameter('meteringmode', 2) # 0 to 2
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())
    # open camera connection
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    # get camera details
    abilities = gp.check_result(gp.gp_camera_get_abilities(camera))
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera))
    # find the date/time setting config item and set it
    if set_datetime(config, abilities.model):
        # apply the changed config
        gp.check_result(gp.gp_camera_set_config(camera, config))
    else:
        print('Could not set date & time')
    # clean up
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
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_list = gp.check_result(gp.gp_camera_autodetect(context))
#    gp.check_result(gp.gp_camera_init(camera, context))
    
#    camera_list = GetCameraList(context)


    # loop through camera list
    for index, (name, addr) in enumerate(camera_list):
        print('Processing camera {:d}:  {:s}  {:s}'.format(index, addr, name))

    # search ports for camera port name and match to this iteration
        port_info_list = gp.check_result(gp.gp_port_info_list_new())
        gp.check_result(gp.gp_port_info_list_load(port_info_list))
        idx = gp.check_result(gp.gp_port_info_list_lookup_path(port_info_list, addr))

    # open this camera and associated context
        camera = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_set_port_info(camera,port_info_list[idx]))
        gp.check_result(gp.gp_camera_init(camera,context))

    # get camera configuration
        config = gp.check_result(gp.gp_camera_get_config(camera,context))

    # grab current value of imageformat and change to JPG
        image_format_old = get_config_value(config,'imageformat')
        set_config_value(camera,config,context,'imageformat',jpgFormat)
        image_format = get_config_value(config,'imageformat')

        print('Changed image format from {:s} to {:s}'.format(image_format_old,image_format))

    # close this camera
        gp.check_result(gp.gp_camera_exit(camera,context))
        
    return 0
Example #50
0
    def get_exposure_status(self):

        status = {}

        error, config = gp.gp_camera_get_config(self.camera)
        gp.check_result(error)

        # error, config_list = gp.gp_camera_list_config(self.camera, self.context)
        # gp.check_result(error)

        status["state"]                 = self.state

        status["autofocus"]             = self._get_config_value(config, "autofocus")
        status["focusmode"]             = self._get_config_value(config, "focusmode")
        status["expprogram"]            = self._get_config_value(config, "expprogram")
        status["exposuremetermode"]     = self._get_config_value(config, "exposuremetermode")
        status["exposurecompensation"]  = self._get_config_value(config, "exposurecompensation")
        status["shutterspeed"]          = self._get_config_value(config, "shutterspeed")
        status["aperture"]              = self._get_config_value(config, "f-number")
        status["iso"]                   = self._get_config_value(config, "iso")

        return status
Example #51
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
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())
    # 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'))
    # 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))
    return 0
Example #53
0
    def get_serialnumber(self):
        error, config = gp.gp_camera_get_config(self.camera)
        gp.check_result(error)

        return self._get_config_value(config, "serialnumber")
Example #54
0
 def config(self):
     res = gp.gp_camera_get_config(*self.camera)
     widget = gp.check_result(res)
     (camera, context) = self.camera
     return Config(widget, camera, context)
Example #55
0
 def _get_widget(self, config_name):
     config = gp.check_result(
                 gp.gp_camera_get_config(self.camera, self.context))
     widget = gp.check_result(
                 gp.gp_widget_get_child_by_name(config, config_name))
     return config, widget
Example #56
0
def get_config_value(key, 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))
    config_value = gp.check_result(gp.gp_widget_get_value(camera_widget_child))
    return config_value
Example #57
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))
Example #58
0
    def set_exposure_compensation(self, compensation):

        error, config = gp.gp_camera_get_config(self.camera)
        gp.check_result(error)

        self._set_config_value(config, "exposurecompensation", str(compensation))