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

6.8. buildRow(): Build one row of region radiobuttons

pickaregion.cgi
# - - -   b u i l d R o w

def buildRow(table, regionList, nRows, rowx):
    '''Build one row of the table of regional radiobuttons.

      [ (table is a table et.Element) and
        (regionList is a list of Region instances) and
        (nRows is the number of rows in the entire table) and
        (0 <= rowx < nRows) ->
           table  +:=  a row displaying a slice across regionList
               for row (rowx) displayed as nRows rows by
               N_REG_COLS columns ]
    '''

Here's a little diagram showing how we slice the region list into columns. The bracketed numbers inside each cell of this diagram show the index of regionList that will appear in that cell of the table.

So in general, the cell in row rowx and column colx of the table displays regionList[nRows*colx + rowx].

pickaregion.cgi
    #-- 1
    # [ table  +:=  a new tr element
    #   tr  :=  that tr element ]
    tr = subElement(table, E.tr())

For the logical that builds one cell of the table, see Section 6.9, “buildRegionCell(): Build one cell of the region radiobuttons table”. Because the last column may not be full, we also check to see if the selected element number is beyond regionList.

pickaregion.cgi
    #-- 2
    # [ tr  +:=  td elements containing the (rowx)th horizontal slice
    #            of regionList ]
    for colx in range(N_REG_COLS):
        #-- 2 body
        # [ tr  +:=  a td element containing a radiobutton labeled with
        #       the name from regionList[nRows*colx+rowx], checked iff
        #       region.reg_code is CHECKED_REGION ]
        regx = nRows * colx + rowx
        if regx < len(regionList):
            buildRegionCell(tr, regionList[regx])