python-3.xpyqtscintillasciteqscintilla

How to embed 'QScintilla' code editor in self-made PyQt GUI?


I'm making a small IDE - mainly for fun! I write everything in Python, and use the PyQt5 library to build the GUI.

Here is a screenshot of the current status:

enter image description here

The code editor itself is a simple QTextEdit() widget - embedded in a QFrame() widget, which itself is embedded in the main window. So the parent to child relationship is as follows (just a bit simplified):

QMainWindow( ) >> QFrame( ) >> QTextEdit( )

I implemented some basic syntax highlighting, using the QSyntaxHighlighter() class from PyQt5. That's great - but not yet awesome. Mr. Bakuriu advised me to take a look at the QScintilla package. Now I struggle with several questions:


Question 1: installing QScintilla

This is the PyQt documentation I can find about QScintilla2: http://pyqt.sourceforge.net/Docs/QScintilla2/ . Apparently on Windows I would need to download the source code of QScintilla2 and build it to a dll-file. Isn't there a more convenient way? For example, some pre-built packages (with installer)?

I also found this download page: http://www.scintilla.org/ScintillaDownload.html . The download page mentions: <<There is no download available containing only the Scintilla DLL. However, it is included in the SciTE executable full download as SciLexer.DLL.>>. So if I interpret this right, I can get the prebuilt Scintilla dll-file in this way. But this download page doesn't mention PyQt anywhere. So I'm wondering if the dll-file will work in PyQt. After all, the download is Scintilla, not QScintilla.

And once I get the dll-file, how do I actually use it to embed a QScintilla editor inside a QFrame?


Question 2: Scintilla or SciTE?

Reading about Scintilla (and QScintilla) I stumbled on SciTE. Someone made a nice installer for this software: http://www.ebswift.com/scite-text-editor-installer.html . Would it be advisable to embed SciTE in my PyQt GUI? And if so - wouldn't I need the 'QSciTE' instead of plain 'SciTE'?


Question 3: Some example code

Once (Q)Scintilla or (Q)SciTE is installed, I will need to get started somehow. If anyone has already embedded Scintilla/SciTE in a PyQt GUI, please post some example code. That would be very helpful :-)


EDIT
After several months I came back to this old question of mine. In the meantime, I have collaborated with my friend Matic Kukovec, which resulted in a nice tutorial on how to use QScintilla:

enter image description here

https://qscintilla.com/

QScintilla is a wonderful tool, but information is very scarce. I hope this initiative can provide the much needed documentation.


Solution

  • Q1:

    You need to install QScintilla and the Python bindings. I don't know for Windows, but it seems available on pip.

    Q2:

    Scintilla is the editor widget. SciTE is a full app using the editor widget, scriptable in Lua language. QScintilla is the Qt port of the Scintilla editor widget.

    Q3:

    A QsciScintilla object is a subclass of QWidget, so you can simply run:

    from PyQt5.QtWidgets import QApplication
    from PyQt5.Qsci import QsciScintilla
    
    app = QApplication([])
    sci = QsciScintilla()
    sci.show()
    app.exec_()