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

29.5. Row._setSuffixCells(): Copy the suffix cells to physical rows

cbchistlib.py
# - - -   R o w . _ s e t S u f f i x C e l l s

    def _setSuffixCells(self, nPhysRows, nPhysCols, rowList):
        '''Produce the suffix cells and add them to the physical rows.

          [ (nPhysRows and nPhysCols are positive ints) and
            (rowList is a list of (nPhysRows) PhysRow instances
            of (nPhysCols) columns each) ->
              rowList  :=  rowList with the last Row.N_SUFFIX_COLS
                  detail cells set to the concrete class's suffix
                  cells ]
        '''

Converting logical column numbers to physical row and column numbers is straightforward: the physical row number is the logical column number divided by MAX_PHYS_COLS, and the physical column number is the remainder.

Here, we distribute the suffix cells over the physical rows, but starting at a logical column number (logBase) such that the last suffix cell lands in the last cell of the last physical row. We use the virtual .suffixes() method from the concrete instance to retrieve the material that will appear in those positions; see Section 29, “class Row: Abstract class for logical rows” for the interface definition.

cbchistlib.py
        #-- 1
        # [ suffixList  :=  the sequence of suffix cells from self
        #   logBase  :=  the logical row index of the first suffix
        #       cell such that the last suffix cell falls in the
        #       last cell of the last row in rowList ]
        suffixList = self.suffixes()
        logBase = nPhysRows*nPhysCols - len(suffixList)
        
        #-- 2
        # [ rowList  :=  rowList with the suffix cells of self copied
        #       into the cells starting with the physical cell
        #       corresponding to logical column (logBase) ]
        for sufx, suffix in enumerate(suffixList):
            #-- 2 body
            logx = logBase + sufx
            rowx, colx = divmod(logx, nPhysCols)
            rowList[rowx].setCell(colx, suffix)