'Paint the line number'

def paintEvent(self, event):

    if (not self.lines):
        return
    painter = QtGui.QPainter(self)
    painter.fillRect(event.rect(), self._base)
    editor = self.editor
    content_offset = editor.contentOffset()
    block = editor.firstVisibleBlock()
    current_block_number = max(0, editor.textCursor().blockNumber())
    width = self.width()
    event_rect_bottom = event.rect().bottom()
    highlight = self._highlight
    highlight_text = self._highlight_text
    window = self._window
    disabled = self._disabled
    fmt = self.formatter
    lines = self.lines
    num_lines = len(self.lines)
    painter.setPen(disabled)
    while block.isValid():
        block_number = block.blockNumber()
        if (block_number >= num_lines):
            break
        block_geom = editor.blockBoundingGeometry(block)
        block_top = block_geom.translated(content_offset).top()
        if ((not block.isVisible()) or (block_top >= event_rect_bottom)):
            break
        rect = block_geom.translated(content_offset).toRect()
        if (block_number == self.highlight_line):
            painter.setPen(highlight_text)
            painter.fillRect(rect.x(), rect.y(), width, rect.height(), highlight)
            painter.setPen(disabled)
        elif (block_number == current_block_number):
            painter.fillRect(rect.x(), rect.y(), width, rect.height(), window)
        line = lines[block_number]
        if (len(line) == 2):
            (a, b) = line
            text = fmt.value(a, b)
        elif (len(line) == 3):
            (old, base, new) = line
            text = fmt.merge_value(old, base, new)
        painter.drawText(rect.x(), rect.y(), (self.width() - (defs.margin * 2)), rect.height(), (Qt.AlignRight | Qt.AlignVCenter), text)
        block = block.next()
