0

I've got a simple editor that I'm trying to port to PyQt6, but have run into a problem with the document modified message. It works fine in PyQt5 but generates 'TypeError: unable to convert a QVariant back to a Python object' message in PyQt6.

# from PyQt6 import QtWidgets
# from PyQt6.Qsci import QsciScintilla
from PyQt5 import QtWidgets
from PyQt5.Qsci import QsciScintilla


class SimplePythonEditor(QsciScintilla):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.SCN_MODIFIED.connect(self._modified)


    # The current documentation https://www.scintilla.org/ScintillaDoc.html#SCN_MODIFIED shows a slightly different set of arguments and order.
    # def _modified(self, modificationType, position, length, linesAdded, text, line, foldLevelNow, foldLevelPrev):
    def _modified(self, position, modificationType, text, length, linesAdded, line, foldLevelNow, foldLevelPrev, token, annotationLinesAdded):        
        print(f'_modified {modificationType=}, {position=}, {length=}, {linesAdded=}, {text=}, {line=}, {foldLevelNow=}, {foldLevelPrev=}, {token=}, {annotationLinesAdded=}')


if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    editor = SimplePythonEditor()
    editor.show()
    app.exec()

Running the code and typing abc in PyQt5 generates the following output

_modified modificationType=1048576, position=0, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1040, position=0, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=8209, position=0, length=1, linesAdded=0, text=b'a', line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1048576, position=1, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1040, position=1, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=17, position=1, length=1, linesAdded=0, text=b'b', line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1048576, position=2, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1040, position=2, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=17, position=2, length=1, linesAdded=0, text=b'c', line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0

I'm on linux my package versions used

PyQt5==5.15.4
PyQt5-Qt5==5.15.2
QScintilla==2.13.0
PyQt6==6.1.1
PyQt6-Qt6==6.1.2
PyQt6-QScintilla==2.13.0
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
shao.lo
  • 4,387
  • 2
  • 33
  • 47

1 Answers1

0

Calling send.SendScintilla(self.SCI_SETMODEVENTMASK, SC_MOD_INSERTTEXT | self.SC_MOD_DELETETEXT) after self.SCN_MODIFIED.connect(self._modified)

without any of the following 4 flags works without error. SC_MOD_CHANGESTYLE SC_MOD_CHANGEFOLD SC_PERFORMED_USER SC_MOD_CHANGEMARKER

shao.lo
  • 4,387
  • 2
  • 33
  • 47