Ejemplo n.º 1
0
def apply_actions_to_photo(actions, image_info, info_not_file, cache,
                           read_only_settings, skip_existing_images, result,
                           report, is_done, image_index, repeat):
    """Apply the action list to one photo."""
    image_info['index'] = image_index
    #open image and check for errors
    photo, result = get_photo(image_info, info_not_file, result)
    if result['abort']:
        close_photo(photo)
        return 'return'
    elif not photo or result['skip']:
        close_photo(photo)
        return 'continue'
    info = photo.info
    info.set('imageindex', image_index)
    image = photo.get_layer().image
    for r in range(repeat):
        info.set('index', image_index * repeat + r)
        info.set('repeatindex', r)
        #update image file & progress dialog box
        progress_result = {}
        send.progress_update_filename(progress_result, info['index'],
                                      info['path'])
        if progress_result and not progress_result['keepgoing']:
            close_photo(photo)
            return 'return'
        #check if already not done
        if skip_existing_images and is_done(photo):
            continue
        if r == repeat - 1:
            photo.get_layer().image = image
        elif r > 0:
            photo.get_layer().image = image.copy()
        #do the actions
        for action_index, action in enumerate(actions):
            #update progress
            progress_result = {}
            send.progress_update_index(progress_result, info['index'],
                                       action_index)
            if progress_result and not progress_result['keepgoing']:
                close_photo(photo)
                return 'return'
            #apply action
            photo, result = apply_action_to_photo(action, photo,
                                                  read_only_settings, cache,
                                                  image_info['path'], result)
            if result['abort']:
                close_photo(photo)
                return 'return'
            elif result['skip']:
                #skip to next image immediately
                continue
    report.extend(photo.report_files)
    close_photo(photo)
    if result['abort']:
        return 'return'
Ejemplo n.º 2
0
def apply_actions_to_photo(actions, image_info, info_not_file,
        cache, read_only_settings, skip_existing_images, result, report,
        is_done, image_index, repeat):
    """Apply the action list to one photo."""
    image_info['index'] = image_index
    #open image and check for errors
    photo, result = get_photo(image_info, info_not_file, result)
    if result['abort']:
        photo.close()
        return 'return'
    elif not photo or result['skip']:
        photo.close()
        return 'continue'
    info = photo.info
    info.set('imageindex', image_index)
    image = photo.get_layer().image
    for r in range(repeat):
        info.set('index', image_index * repeat + r)
        info.set('repeatindex', r)
        #update image file & progress dialog box
        progress_result = {}
        send.progress_update_filename(progress_result, info['index'],
            info['path'])
        if progress_result and not progress_result['keepgoing']:
            photo.close()
            return 'return'
        #check if already not done
        if skip_existing_images and is_done(photo):
            continue
        if r == repeat - 1:
            photo.get_layer().image = image
        elif r > 0:
            photo.get_layer().image = image.copy()
        #do the actions
        for action_index, action in enumerate(actions):
            #update progress
            progress_result = {}
            send.progress_update_index(progress_result, info['index'],
                action_index)
            if progress_result and not progress_result['keepgoing']:
                photo.close()
                return 'return'
            #apply action
            photo, result = apply_action_to_photo(action, photo,
                read_only_settings, cache, image_info['path'], result)
            if result['abort']:
                photo.close()
                return 'return'
            elif result['skip']:
                #skip to next image immediately
                continue
    report.extend(photo.report_files)
    photo.close()
    if result['abort']:
        return 'return'
Ejemplo n.º 3
0
def verify_images(image_infos, repeat):
    """Filter invalid images out.

    Verify if images are not corrupt. Show the invalid images to
    the user. If no valid images are found, show an error to the user.
    Otherwise show the valid images to the user.

    :param image_infos: list of image info dictionaries
    :type image_infos: list of dictionaries
    :returns: None for error, valid image info dictionaries otherwise
    """
    #show dialog
    send.frame_show_progress(title=_("Checking images"),
                             parent_max=len(image_infos),
                             message=PROGRESS_MESSAGE)
    #verify files
    valid = []
    invalid = []
    for index, image_info in enumerate(image_infos):
        result = {}
        send.progress_update_filename(result, index, image_info['path'])
        if not result['keepgoing']:
            return
        openImage.verify_image(image_info, valid, invalid)
    send.progress_close()
    #show invalid files to the user
    if invalid:
        result = {}
        send.frame_show_files_message(
            result,
            message=_('Phatch can not handle %d image(s):') % len(invalid),
            title=ct.FRAME_TITLE % ('', _('Invalid images')),
            files=invalid)
        if result['cancel']:
            return
    #Display an error when no files are left
    if not valid:
        log_error(_("Sorry, no valid files found"))
        return
    #number valid items
    for index, image_info in enumerate(valid):
        image_info['index'] = index * repeat
    #show valid images to the user in tree structure
    result = {}
    send.frame_show_image_tree(result,
                               valid,
                               widths=(200, 40, 200, 200, 200, 200, 60),
                               headers=TREE_HEADERS,
                               ok_label=_('C&ontinue'),
                               buttons=True)
    if result['answer']:
        return valid
Ejemplo n.º 4
0
def verify_images(image_infos, repeat):
    """Filter invalid images out.

    Verify if images are not corrupt. Show the invalid images to
    the user. If no valid images are found, show an error to the user.
    Otherwise show the valid images to the user.

    :param image_infos: list of image info dictionaries
    :type image_infos: list of dictionaries
    :returns: None for error, valid image info dictionaries otherwise
    """
    #show dialog
    send.frame_show_progress(title=_("Checking images"),
        parent_max=len(image_infos),
        message=PROGRESS_MESSAGE)
    #verify files
    valid = []
    invalid = []
    for index, image_info in enumerate(image_infos):
        result = {}
        send.progress_update_filename(result, index, image_info['path'])
        if not result['keepgoing']:
            return
        openImage.verify_image(image_info, valid, invalid)
    send.progress_close()
    #show invalid files to the user
    if invalid:
        result = {}
        send.frame_show_files_message(result,
            message=_('Phatch can not handle %d image(s):') % len(invalid),
            title=ct.FRAME_TITLE % ('', _('Invalid images')),
            files=invalid)
        if result['cancel']:
            return
    #Display an error when no files are left
    if not valid:
        send.frame_show_error(_("Sorry, no valid files found"))
        return
    #number valid items
    for index, image_info in enumerate(valid):
        image_info['index'] = index * repeat
    #show valid images to the user in tree structure
    result = {}
    send.frame_show_image_tree(result, valid,
        widths=(200, 40, 200, 200, 200, 200, 60),
        headers=TREE_HEADERS,
        ok_label=_('C&ontinue'), buttons=True)
    if result['answer']:
        return valid