Next / Previous / Contents / Shipman's homepage

22. class OutBlock: One output block

An instance of this class represents one of the pieces into which an input line has been cut. It is a base class for two virtual classes: the first or only piece of an input line is represented by Section 23, “class FirstBlock: Block for the first or only line”, and each overflow piece is represented by Section 24, “class OverflowBlock: Overflow continuation block”.

Each instance has an .__isBreak attribute which is initially False. To make a block start in a new column, call the .setBreak() method, which set this attribute to True.

listext2
# - - - - -   c l a s s   O u t B l o c k

class OutBlock(object):
    '''Represents one output block.

      Exports:
        OutBlock(text, goodBreak, bodyLayout):
          [ (text is a string) and
            (goodBreak is True iff this line starts with the
            break string) and
            (bodyLayout is a BodyLayout instance) ->
              return a new OutBlock instance representing that
              text with that body layout and no break marked ]
        .text:         [ as passed to constructor ]
        .bodyLayout:   [ as passed to constructor ]
        .goodBreak:    [ as passed to constructor ]
        .isBlank:
          [ if text is empty or contains only whitespace -> True
            else -> False ]
        .setBreak():   [ self  :=  self marked with a column break ]
        .isBreak():
          [ if self is marked with a column break -> True
            else -> False ]
        .render(parent):    # Virtual method
          [ if self is marked with a break ->
              parent  +:=  a new block element formatted according
                  to Args() and self.bodyLayout, with a preceding
                  line break
            else ->
              parent  +:=  a new block element formatted according
                  to Args() and self.bodyLayout ]
      State/Invariants:
        .__isBreak:
           [ True iff this block should start a new column;
             read/write ]
    '''
    def render(self, parent):
        raise NotImplementedYet("OutBlock.render() is a virtual method.")

22.1. OutBlock.__init__(): Constructor

listext2
# - - -   O u t B l o c k . _ _ i n i t _ _

    def __init__(self, text, goodBreak, bodyLayout):
        '''Constructor.
        '''
        self.text = text
        self.goodBreak = goodBreak
        self.bodyLayout = bodyLayout
        self.__isBreak = False
        self.isBlank =(( len(text) == 0) or text.isspace())