Python: Qt=>PyQt5 ??

530
.
aNNiPAk

Ребят, проблемка нарисовалась, решил я значит прикрутить к QPlainTextEdit нумерацию строк с левой стороны, нашел пример [url=http://doc.crossplatform.ru/qt/4.7.x/widgets-codeeditor.html][/url], да вот с реализацией этого примера вышли затруднения:

Код (+/-)
class LineNumberArea(QWidget):
    def __init__(self, editor):
        QWidget.__init__(self, editor)
        self.codeEditor = editor

    def sizeHint(self):
        return self.QSize(self.codeEditor.lineNumberAreaWidth(), 0)

    def paintEvent(self, event):
        QPaintEvent.__init__(event)
        self.codeEditor.lineNumberAreaPaintEvent(event)

class CodeEditor(QPlainTextEdit):
    def __init__(self, parent):
        QPlainTextEdit.__init__(self, parent)
        self.lineNumberArea = LineNumberArea(self)
        parent.blockCountChanged['int'].connect(self.updateLineNumberAreaWidth(int))
        # parent.connect(self, self.SIGNAL(self.blockCount()), self, self.SLOT(self.updateLineNumberAreaWidth(int)))
        # parent.connect(self, self.SIGNAL(self.updateRequest(QRect, int)), self, self.SLOT(self.updateLineNumberArea(QRect, int)))
        # parent.connect(self, self.SIGNAL(self.cursorPositionChanged()), self, self.SLOT(self.highlightCurrentLine()))
        self.updateLineNumberAreaWidth(0)
        self.highlightCurrentLine()

    def lineNumberAreaPaintEvent(self, event):
        painter = QPainter(self.lineNumberArea)
        painter.fillRect()
        block = self.firstVisibleBlock()
        blockNumber = block.blockNumber()
        top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
        bottom = top + self.blockBoundingRect(block).height()
        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                number = blockNumber + 1
                painter.setPen(Qt.black)
                painter.drawText(0, top, self.lineNumberArea.width(), self.fontMetrics().height(), Qt.AlignRight, number)
            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            blockNumber += 1

    def highlightCurrentLine(self):
        extraSelections = QTextEdit.ExtraSelection
        if not self.isReadOnly():
            selection = QTextEdit.ExtraSelection()
            lineColor = self.QColor(Qt.yellow).lighter(160)
            selection.format.setBackground(lineColor)
            selection.format.setProperty(QTextFormat.FullWidthSelection, True)
            selection.cursor = self.textCursor()
            selection.cursor.clearSelection()
            extraSelections.append(selection)
        self.setExtraSelections(extraSelections)

    def resizeEvent(self, e):
        QPlainTextEdit.resizeEvent(self, e)
        cr = self.contentsRect()
        self.lineNumberArea.setGeometry(self.QRect(cr.left(), cr.top(), self.lineNumberAreaWidth(), cr.height()))

    def updateLineNumberArea(self, rect, dy):
        if dy != 0:
            self.lineNumberArea.scroll(0, dy)
        else:
            self.lineNumberArea.update(0, rect.y(), self.lineNumberArea.width(), rect.height())
        if rect.contains(self.viewport().rect()):
            self.updateLineNumberAreaWidth(0)

    def updateLineNumberAreaWidth(self, UnnamedParameter1):
        self.setViewportMargins(self.lineNumberAreaWidth(), 0, 0, 0)

    def lineNumberAreaWidth(self):
        digits = 1
        print(self.blockCount())
        max = self.Qmax(1, 2) #self.blockCount())
        while max >= 10:
            max /= 10
            digits += 1
        space = 3 + self.fontMetrics().width(self.QLatin1Char('9')) * digits
        return space

Подключаю я так:
self.kkk = CodeEditor(self.QPlainTextEdit)

Но при запуске наблюдается ошибка, вида(73 строка):
AttributeError: 'CodeEditor' object has no attribute 'Qmax'

Также ругается и на атрибут QLatin1Char
Почему она возникает и как её исправить, ведь CodeEditor вроде должен наследоваться от QCore?
Всего: 1