Exemple #1
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
Exemple #2
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
Exemple #3
0
 def is_done(self, photo):
     """Method used for resuming when a batch was interrupted.
     Check if this image has been done already."""
     #check if there are not forbidden tags (new.*)
     try:
         #is_done_info is only available on save actions
         folder, filename, typ = self.is_done_info(photo.info)
     except KeyError:
         return False
     #check if file exists
     if not os.path.exists(filename):
         return False
     #check if file is valid
     return openImage.verify_image({'path': filename}, [], [])
Exemple #4
0
 def is_done(self, photo):
     """Method used for resuming when a batch was interrupted.
     Check if this image has been done already."""
     #check if there are not forbidden tags (new.*)
     try:
         #is_done_info is only available on save actions
         folder, filename, typ = self.is_done_info(photo.info)
     except KeyError:
         return False
     #check if file exists
     if not os.path.exists(filename):
         return False
     #check if file is valid
     return openImage.verify_image({'path': filename}, [], [])