Next / Previous / Contents / TCC Help System / NM Tech homepage

12. class FormPhotoSet: All photos for one name

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.

          [ birdId is a bird form code as an abbr.BirdID ->
              return a new, empty FormPhotoSet for birdId ]
        .birdId:     [ as passed to constructor; read-only ]
          [ archImage is a photo catalog entry as an
            archindex.ArchImage instance ->
              self  :=  self with archImage added ]
          [ generate the ArchImage instances in self, in
            descending order by image size, with catalog number
            as a secondary key ]
          [ returns the relative path name to the page that
            displays this form ]
          [ 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:


where -area is the image's area in square millimeters as a float, negated, and catNo is the image's catalog number.

          [ 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 ]