'Return True iff this container has non whitespace text'

def has_text(self):

    if hasattr(self, 'text'):
        if self.text.strip():
            return True
    if hasattr(self, 'contents'):
        for child in self.contents:
            if child.has_text():
                return True
    for item in self.contents:
        if isinstance(item, (Plot, ImageBlock, Canvas, CR)):
            return True
    return False
