Each instance of a
FormPhotoSet contains all
the images that have the same inverted English name.
# - - - - - c l a s s F o r m P h o t o S e t class FormPhotoSet: '''Container for photos that have birds with a given English name. Exports: FormPhotoSet(birdId): [ birdId is a bird form code as an abbr.BirdID -> return a new, empty FormPhotoSet for birdId ] .birdId: [ as passed to constructor; read-only ] .addArchImage(archImage): [ archImage is a photo catalog entry as an archindex.ArchImage instance -> self := self with archImage added ] .genArchImages(): [ generate the ArchImage instances in self, in descending order by image size, with catalog number as a secondary key ] .pathName(): [ returns the relative path name to the page that displays this form ] .buildPage(): [ form page for self := content displaying thumbnails and catalog data for self ]
One internal data structure suffices to hold all the
ArchImage instances of the set. One of the
author's standard Python tricks is to keep a set of values
in a dictionary, and then structure the key so that, when
sorted, it produces the values in the desired order.
As discussed in Section 3.2, “The form page”, the principal sort order of images is in descending order by image area. In case two images happen to have the same area, their catalog number is used as a tie-breaker. Hence, the dictionary key is a tuple of two values:
-area is the image's area in square
millimeters as a float, negated, and
catNo is the
image's catalog number.
State/Invariants: ._sizeMap: [ a dictionary whose values are the ArchImage instances contained in self, and each key is a 2-tuple whose first element is the image's area in square mm as a float, negated, and the second element is the image's catalog number ] '''