def main():
    def callback(level, domain, string, data=None):
        print('Callback: level =', level, ', domain =', domain, ', string =', string)
        if data:
            print('Callback data:', data)
    camera = gp.Camera()
    # add our own callback
    print('Using Python callback')
    print('=====================')
    callback_obj = gp.check_result(
        gp.gp_log_add_func(gp.GP_LOG_VERBOSE, callback))
    print('callback_obj', callback_obj)
    # create an error
    gp.gp_camera_init(camera)
    # uninstall callback
    del callback_obj
    # add our own callback, with data
    print('Using Python callback, with data')
    print('================================')
    callback_obj = gp.check_result(
        gp.gp_log_add_func(gp.GP_LOG_VERBOSE, callback, 'some data'))
    print('callback_obj', callback_obj)
    # create an error
    gp.gp_camera_init(camera)
    # uninstall callback
    del callback_obj
    # set gphoto2 to use Python's logging directly
    print('Using Python logging')
    print('====================')
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    # create an error
    gp.gp_camera_init(camera)
    return 0
Exemplo n.º 2
0
def main():
    def callback(level, domain, string, data=None):
        print('Callback: level =', level, ', domain =', domain, ', string =',
              string)
        if data:
            print('Callback data:', data)

    context = gp.Context()
    camera = gp.Camera()
    # add our own callback
    print('Using Python callback')
    print('=====================')
    callback_id = gp.check_result(
        gp.gp_log_add_func(gp.GP_LOG_VERBOSE, callback))
    print('callback_id', callback_id)
    # create an error
    gp.gp_camera_init(camera, context)
    # uninstall callback
    gp.check_result(gp.gp_log_remove_func(callback_id))
    # add our own callback, with data
    print('Using Python callback, with data')
    print('================================')
    callback_id = gp.check_result(
        gp.gp_log_add_func(gp.GP_LOG_VERBOSE, callback, 'some data'))
    print('callback_id', callback_id)
    # create an error
    gp.gp_camera_init(camera, context)
    # uninstall callback
    gp.check_result(gp.gp_log_remove_func(callback_id))
    # set gphoto2 to use Python's logging directly
    print('Using Python logging')
    print('====================')
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    # create an error
    gp.gp_camera_init(camera, context)
    return 0
Exemplo n.º 3
0
    def __init__(self,
                 iso=200,
                 resolution=(1920, 1080),
                 rotation=0,
                 flip=False,
                 delete_internal_memory=False,
                 init=True):
        BaseCamera.__init__(self, iso, resolution, delete_internal_memory)
        self._gp_logcb = gp.check_result(
            gp.gp_log_add_func(gp.GP_LOG_VERBOSE, gp_log_callback))
        self._preview_compatible = True
        self._preview_viewfinder = False
        self._preview_hflip = False
        self._capture_hflip = flip
        self._rotation = rotation

        if init:
            self._initialize()
Exemplo n.º 4
0
    def _specific_initialization(self):
        """Camera initialization.
        """
        self._gp_logcb = gp.check_result(
            gp.gp_log_add_func(gp.GP_LOG_VERBOSE, gp_log_callback))
        abilities = self._cam.get_abilities()
        self._preview_compatible = gp.GP_OPERATION_CAPTURE_PREVIEW ==\
            abilities.operations & gp.GP_OPERATION_CAPTURE_PREVIEW
        if not self._preview_compatible:
            LOGGER.warning(
                "The connected DSLR camera is not compatible with preview")
        else:
            try:
                self.get_config_value('actions', 'viewfinder')
                self._preview_viewfinder = True
            except ValueError:
                self._preview_viewfinder = False

        self.set_config_value('imgsettings', 'iso', self.preview_iso)
        self.set_config_value('settings', 'capturetarget', 'Memory card')
Exemplo n.º 5
0
def main():
    error = False
    configure_logging()
    write_log("Pibooth version installed: {}".format(pibooth.__version__))

    plugin_manager = create_plugin_manager()
    config = PiConfigParser("~/.config/pibooth/pibooth.cfg", plugin_manager)

    # Register plugins
    plugin_manager.load_all_plugins(
        config.gettuple('GENERAL', 'plugins', 'path'),
        config.gettuple('GENERAL', 'plugins_disabled', str))

    write_log("Installed plugins: {}".format(", ".join([
        plugin_manager.get_friendly_name(p)
        for p in plugin_manager.list_external_plugins()
    ])))

    if not gp:
        write_log("gPhoto2 not installed, cannot diagnose connected DSLR")
        sys.exit(1)

    gp_log_callback = gp.check_result(
        gp.gp_log_add_func(gp.GP_LOG_VERBOSE, gp_logging))
    write_log("Listing all connected DSLR camera")
    cameras_list = camera_connected()

    if not cameras_list:
        write_log('No compatible DSLR camera detected')
        sys.exit(1)

    cameras_list = sorted(cameras_list, key=lambda x: x[0])
    for index, (name, addr) in enumerate(cameras_list):
        write_log("{:02d} : addr-> {}  name-> {}".format(index, addr, name))

    write_log("Stating diagnostic of connected DSLR camera", True)
    camera = gp.Camera()
    camera.init()

    abilities = camera.get_abilities()
    preview_compat = gp.GP_OPERATION_CAPTURE_PREVIEW ==\
        abilities.operations & gp.GP_OPERATION_CAPTURE_PREVIEW
    write_log("* Preview compatible: {}".format(preview_compat))
    capture_compat = gp.GP_OPERATION_CAPTURE_IMAGE ==\
        abilities.operations & gp.GP_OPERATION_CAPTURE_IMAGE
    write_log("* Capture compatible: {}".format(capture_compat))

    if capture_compat:
        try:
            print_config(camera.get_config())

            write_log("Testing commands used by pibooth", True)

            set_config_value(camera, 'imgsettings', 'iso', '100')
            set_config_value(camera, 'settings', 'capturetarget',
                             'Memory card')

            viewfinder = get_config_value(camera, 'actions', 'viewfinder')
            if viewfinder is not None:
                set_config_value(camera, 'actions', 'viewfinder', 1)

            write_log("Take capture preview")
            camera.capture_preview()

            if viewfinder is not None:
                set_config_value(camera, 'actions', 'viewfinder', 0)

            write_log("Take a capture")
            gp_path = camera.capture(gp.GP_CAPTURE_IMAGE)

            write_log("Download file from DSLR")
            camera_file = camera.file_get(gp_path.folder, gp_path.name,
                                          gp.GP_FILE_TYPE_NORMAL)

            write_log("Save capture locally from memory buffer")
            data = camera_file.get_data_and_size()
            with open(APPNAME + '.raw', 'wb') as fd:
                fd.write(data)
            image = Image.open(io.BytesIO(data))
            image.save(APPNAME + '.jpg')

        except Exception as ex:
            write_log("ABORT   : exception occures: {}".format(ex), True)
            error = True

    if not error:
        write_log("SUCCESS : diagnostic completed", True)

    del gp_log_callback
    camera.exit()

    write_log(
        "If you are investigating why pibooth does not work with your DSLR camera,"
    )
    write_log(
        "please paste the content of generated file '{}'".format(APPNAME +
                                                                 '.log'))
    write_log("on https://github.com/pibooth/pibooth/issues")
Exemplo n.º 6
0
 def __init__(self):
     gp.check_result(gp.gp_log_add_func(gp.GP_LOG_VERBOSE, _log_callback))
     self._camera = gp.Camera()