metapho package

Subpackages

Submodules

metapho.imagelist module

class metapho.imagelist.ImageListIterator[source]

Bases: object

metapho.imagelist.add_images(newlist_or_img)[source]

Pass either a list of MetaphoImage or a single MetaphoImage.

metapho.imagelist.advance()[source]

Increment cur_imgno by 1 if possible, else raise IndexError

metapho.imagelist.clear_images()[source]
metapho.imagelist.current_image()[source]
metapho.imagelist.current_imageno()[source]
metapho.imagelist.get_image(imgno)[source]
metapho.imagelist.image_list()[source]
metapho.imagelist.num_images()[source]
metapho.imagelist.num_valid_images()[source]
metapho.imagelist.pop_image(imgno=None, advance=False)[source]

Remove the indicated image from the list and return it. If img is None, remove the current image. If deleting the current image, leave the pointer on the image before the removed one unless advance is True; if popping any other image, don’t move the pointer.

metapho.imagelist.print_imagelist()[source]

For debugging

metapho.imagelist.remove_image(img=None)[source]

Remove the indicated image. If img is None, remove the current image. If the cur_imgno pointer was pointing to the removed image, leave the pointer on the image before the removed one, otherwise don’t disturb the pointer.

metapho.imagelist.retreat()[source]

Decrement cur_imgno by 1 if possible, else raise IndexError

metapho.imagelist.set_current_image(im)[source]

Can raise ValueError if im isn’t in the list

metapho.imagelist.set_current_imageno(val)[source]

metapho.metapho module

The base class for metapho images. Programs with a GUI can inherit from MetaphoImage.

class metapho.metapho.MetaphoImage(filename, displayed=True)[source]

Bases: object

An image, with additional info such as rotation and tags.

add_tag(tagno)[source]
classmethod clean_up_nonexistent_files(topdir)[source]

For any file that was referenced in a tag file but doesn’t exist on disk, see if perhaps it’s been moved to a different subdirectory under topdir. If so, adjust file path appropriately.

Return a set of filenames removed in case the caller wants to warn the user or take other action. XXX Maybe better to convert to a list before returning?

delete()[source]

Delete the image file FROM DISK, and the image object from the imageList. DOES NOT ASK FOR CONFIRMATION – do that (if desired) from the calling program.

classmethod find_nonexistent_files()[source]

Returns a list of images in the imagelist that don’t exist on disk.

classmethod image_index(filename)[source]

Find a name in the global image list. Return index, or None.

remove_tag(tagno)[source]
classmethod tagged_images()[source]

Return a dictionary of { tag: [list of tagged images] }

toggle_tag(tagno)[source]

This is only called from gtk metapho and tkpho. Tk metapho has its own toggle handler. tagno should be a string, the actual tag.

metapho.metapho.displayed_images()[source]
metapho.metapho.find_in_displayed_images()[source]

Return index, total

metapho.metapho.num_displayed_images()[source]
metapho.metapho.num_hidden_images()[source]
metapho.metapho.num_total_images()[source]

metapho.tagger module

class metapho.tagger.Tagger[source]

Bases: object

Manages tags for images.

IGNORE_DIRNAMES = ['html', 'web', 'bad', '.*_assets$']
SKIP_EXTENSIONS = ['.cr2', '.arw', '.xcf', '.mvi', '.avi', '.mov', '.thm', '.mp4', '.mkv', '.pto', '.txt', '.wav', '.mp3', '.xml', '.pp3']
add_tag(tag, img, category=None)[source]

Add a tag to the given image, in the given category or else the current one. img is a metapho.MetaphoImage. tag may be a string, which can be a new string or an existing one, or an integer index into the tag list. Return the index (in the global tags list) of the tag just added.

change_tag(entryno, newstr)[source]

Update a tag’s string. Called on focus_out from one of the text entries (in GUI metapho). The entryno should be the same as the index in the current category. Changes it for all categories, not just the current one.

check_commondir(d)[source]

Keep track of the dir common to all directories we use: XXX commondir code is still somewhat experimental.

clear_tags(img)[source]
find_untagged_files(topdir)[source]

Return a list of untagged files and a list of directories in which nothing is tagged, under topdir.

classmethod ignore_directory(d, path=None)[source]

Detect directory names that don’t need to be indexed separately and aren’t likely to have a Tags file; for instance, those that likely contain copies of what’s in the parent, or small copies for a web page. Also, you can skip tagging by creating a file named NoTags.

img_has_tags_in(img, cat)[source]
match_tag(pattern)[source]

Return a list of tags matching the pattern.

static print_files_by_directory(filelist)[source]

Given a list of pathnames, group them by which directory they belong to and print them in an organized way.

print_imagelist()[source]

Similar to imagelist.print_imagelist() except it also prints tags.

process_tag(tagname, filenames)[source]

After reading a tag from a tags file, add it to the global tags list if it isn’t there already, and add the given filenames. Filenames can be relpaths or absolute normpaths.

read_all_tags_for_images()[source]

Read tags in all directories used by known images, plus the common dir, plus . Leave the pointer where it was before.

read_tags(dirname, recursive=True)[source]

Read in tags from files named in the given directory, and tag images in the imagelist appropriately. (Don’t add any new images to the imagelist.) Tags will be appended to the tag_list. If recursive is True, we’ll also look for Tags files in subdirectories.

remove_tag(tag, img)[source]
rename_category(old, new)[source]
static split_by_line_length(s, linelen, prefix='')[source]

Given a long string, split it into lines no longer than linelen, with each line optionally prefixed, e.g. with indentation. Currently this splits only at spaces, not tabs.

tagdict_for_img(img)[source]

Returns { catname: [tagno, tagnno] }

tagname_to_tagno(tagname)[source]

Given a tag name, return its index in the list. -1 if not found.

toggle_tag(tagno, img)[source]

Toggle tag number tagno for the given img.

write_tag_file()[source]

Save the current set of tags to a Tags file chosen from the top-level directory used in the images we’ve seen. If there was a previous Tags file there, it will be saved as Tags.bak.

metapho.tagger.Usage()[source]
metapho.tagger.commonprefix(paths)[source]
metapho.tagger.main()[source]

The script linked as notags: Read tags and report any inconsistencies: images in the Tags file that don’t exist on disk, images on disk that aren’t in ./Tags.

Module contents

metapho: an image tagger and viewer.

class metapho.Tagger[source]

Bases: object

Manages tags for images.

IGNORE_DIRNAMES = ['html', 'web', 'bad', '.*_assets$']
SKIP_EXTENSIONS = ['.cr2', '.arw', '.xcf', '.mvi', '.avi', '.mov', '.thm', '.mp4', '.mkv', '.pto', '.txt', '.wav', '.mp3', '.xml', '.pp3']
add_tag(tag, img, category=None)[source]

Add a tag to the given image, in the given category or else the current one. img is a metapho.MetaphoImage. tag may be a string, which can be a new string or an existing one, or an integer index into the tag list. Return the index (in the global tags list) of the tag just added.

change_tag(entryno, newstr)[source]

Update a tag’s string. Called on focus_out from one of the text entries (in GUI metapho). The entryno should be the same as the index in the current category. Changes it for all categories, not just the current one.

check_commondir(d)[source]

Keep track of the dir common to all directories we use: XXX commondir code is still somewhat experimental.

clear_tags(img)[source]
find_untagged_files(topdir)[source]

Return a list of untagged files and a list of directories in which nothing is tagged, under topdir.

classmethod ignore_directory(d, path=None)[source]

Detect directory names that don’t need to be indexed separately and aren’t likely to have a Tags file; for instance, those that likely contain copies of what’s in the parent, or small copies for a web page. Also, you can skip tagging by creating a file named NoTags.

img_has_tags_in(img, cat)[source]
match_tag(pattern)[source]

Return a list of tags matching the pattern.

static print_files_by_directory(filelist)[source]

Given a list of pathnames, group them by which directory they belong to and print them in an organized way.

print_imagelist()[source]

Similar to imagelist.print_imagelist() except it also prints tags.

process_tag(tagname, filenames)[source]

After reading a tag from a tags file, add it to the global tags list if it isn’t there already, and add the given filenames. Filenames can be relpaths or absolute normpaths.

read_all_tags_for_images()[source]

Read tags in all directories used by known images, plus the common dir, plus . Leave the pointer where it was before.

read_tags(dirname, recursive=True)[source]

Read in tags from files named in the given directory, and tag images in the imagelist appropriately. (Don’t add any new images to the imagelist.) Tags will be appended to the tag_list. If recursive is True, we’ll also look for Tags files in subdirectories.

remove_tag(tag, img)[source]
rename_category(old, new)[source]
static split_by_line_length(s, linelen, prefix='')[source]

Given a long string, split it into lines no longer than linelen, with each line optionally prefixed, e.g. with indentation. Currently this splits only at spaces, not tabs.

tagdict_for_img(img)[source]

Returns { catname: [tagno, tagnno] }

tagname_to_tagno(tagname)[source]

Given a tag name, return its index in the list. -1 if not found.

toggle_tag(tagno, img)[source]

Toggle tag number tagno for the given img.

write_tag_file()[source]

Save the current set of tags to a Tags file chosen from the top-level directory used in the images we’ve seen. If there was a previous Tags file there, it will be saved as Tags.bak.