PySide6 QScintilla binding

418 views Asked by At

I know there is no official link between qscintilla and pyside6, but I would like to know if there is any alternative or unofficial port.

In search of information, I found only an empty repository http://gitorious.org/pyside-qscintilla and (as I understand it) a build script https://github.com/LuaDist/scintilla/tree/master/qt/ScintillaEditPy

2

There are 2 answers

0
Misinahaiya On

As mentioned by @ekhmoro, there are probably never been a QScintilla version of the Scintilla control.

However, here are a list of my suggested alternative text editors:

  • PyQode: claimed to be the "alternative of the QScintilla control", however the official Qt port, Qode, is achieved by the authors (https://github.com/pyQode/pyqode.qt). The Python port of Qode seems still activating by the authors, but it's almost dead (the latest release, 2.8.0, is about 8 years ago). Official source code link: https://github.com/pyQode/pyqode.python. Official installation link: https://pypi.org/project/pyqode3-core/, via pip install pyqode3-core.
  • qutepart: claims to support both PyQt and PySide version, however it seems that only PyQt is supported; but you can translate the source code (https://github.com/andreikop/qutepart) into PySide. Translate pyqtSlot into Slot and pyqtSignal into Signal, etc.
  • Implement your own?

Yes, you can definitely implement your own QsciScintilla component with just one PySide (without any additional libraries!) See the example page below:

https://doc.qt.io/qtforpython-6.2/examples/example_widgets__codeeditor.html

  1. Adjust the font by the default system's monospace font by:
QFont monospace = QFont();
monospace.setStyleHint(QFont::Monospace);
textEdit::setFont(monospace);
// This will lead the program figuring what 
// font should it use by itself.
monospace: QFont = QFont()
monospace.setStyleHint(QFont.Monospace)
textEdit.setFont(monospace)
# This will lead the program figuring what
# font should it use by itself.
  1. For syntax highlighting,

Refer to the following link. You will find a way that perfectly combines QTextCharFormat with QPlainTextEdit, via QSyntaxHighlighter.

https://doc.qt.io/qtforpython-6/examples/example_widgets_richtext_syntaxhighlighter.html

These simple little code are just equivalent to those bulky QsciLexer*.

  1. For other features

You might like to compare the feature of QScintilla and the Qt Rich Text engine. In this case, Manuals are your good friends. You can always check the documentation and see the similar stuff between PySide::Qt-RichText and Qsci::QsciScintilla. For instance,

qsci_editor.setWrapMode(QsciScintilla.WrapWord)
# are equivalent to
pyside_editor.setWordWrapMode(QTextOption.WordWrap)
# While QTextOption::NoWrap == QsciScintilla::WrapNone;, etc.

And finally, don't forget you have StackOverflow.

0
Ioan Călin On

Scintilla has been working with Qt and C++ for a long time - the binding is in the official Scintilla source code and it is under the Scintilla license (wikipedia calls this license the Historical Permission Notice and Disclaimer). You don't need QScintilla from Riverbank Computing for that.

For using Scintilla with PySide6 you can try my simple binding - you'll need to build your own wheel and I have tested the binding only on windows with PySide6 6.6 and Python 3.12. I've released my binding under MIT.

Somebody also made a feature request on bugreports.qt.io - you can also wait and see if the Qt Company will decide to implement the binding, but there has been no activity there for more than a year.

screenshot of pyside6 scintilla demo app