Ejemplo n.º 1
0
def _check_line(line, filename, lineno):
    maxlinelen = constants.MAX_LINE_LENGTH
    
    if (lenignoretag(line) > maxlinelen):
        prefix = _warn_message_prefix(filename, lineno)
        #print(':'.join(prefix + ['Line too long:']))
        _show_message(':'.join(prefix + ['Text too long ']) +
                      '(' + str(lenignoretag(line)) + '):' +
                      ''.join([line[:30], '...']))
Ejemplo n.º 2
0
def wrap(block):
    """ Wraps a block of text
    
    Arguments:
    block -- Script block to be word wrapped
        
    """
    dowrap = False
    maxlinelen = constants.MAX_LINE_LENGTH
    newline = constants.NEWLINE
    text = block.gettext()
    
        
    # Only wrap if one or more lines exceed the max length
    if (any([lenignoretag(line) > maxlinelen for line in text])):
        dowrap = True
    
    if (not dowrap):
        return text
        
        
    # Wrap segment #
    
    tokens = [word for line in text for word in _tokenize(line)]

    line = ''
    newtext = []
    n = 0
    for t in tokens:
        if (n + lenignoretag(t) <= maxlinelen):
            n += lenignoretag(t)
            line += t
        else:
            # Line is full
            newtext.append(line.rstrip())
            n = 0
            if (t != ' '):
                line = t + ' '
                n += lenignoretag(t)
            else:
                line = ''
            
    newtext.append(line)
    newtext = [s + newline for s in newtext]
        
    #print("N:", len(newtext))
    #print("Newtext:", newtext)
    block.settext(newtext)