Reputation: 9650
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:
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:
QScintilla is a wonderful tool, but information is very scarce. I hope this initiative can provide the much needed documentation.
Upvotes: 2
Views: 3552
Reputation: 9650
Thank you Mr./Mss. @DisplayName for your answer. I got it working and I put a little sidenote here for the Windows users.
My system is as follows:
.exe
installer from https://www.riverbankcomputing.com/software/pyqt/download5)_
STEP 1:
Download the file QScintilla-2.9.2-cp35-none-win_amd64.whl
from the site https://pypi.python.org/pypi/QScintilla .
Put the file in the folder:
C: \ .. \ Anaconda \ Scripts \
We will use this .whl
file to do the installation of QScintilla.
_
STEP 2:
Open the Windows cmd
tool with Administrator privileges! Now type the following command:
> cd "C:\..\Anaconda\Scripts"
This brings the cmd
shell to the right spot. Now type the following command:
> pip3 install QScintilla
If all goes well, you get the following message:
> pip3 install QScintilla
Collecting QScintilla
Downloading QScintilla-2.9.2-cp35-none-win_amd64.whl (1.6MB)
100% |################################| 1.6MB 984kB/s
Collecting PyQt5 (from QScintilla)
Downloading PyQt5-5.6-cp35-none-win_amd64.whl (74.7MB)
100% |################################| 74.7MB 23kB/s
Collecting sip (from PyQt5->QScintilla)
Downloading sip-4.18-cp35-none-win_amd64.whl (46kB)
100% |################################| 51kB 5.7MB/s
Installing collected packages: sip, PyQt5, QScintilla
..
Successfully installed PyQt5-5.6 QScintilla-2.9.2 sip-4.18
_
STEP 3:
I did not get the message "Successfully installed" from the first shot. Instead I got the following error message:
PermissionError: [Errno 13] Permission denied: 'C:\..\anaconda\Lib\site-packages\sip.pyd'
Apparently the file sip.pyd
sitting in the directory C:\..\anaconda\Lib\site-packages
could not be accessed. So I opened another Windows command shell (of course again with Administrator privileges!) and typed the following command:
> icacls "C:\..\Anaconda\Lib\site-packages" /grant "Administrators":(OI)(CI)F /T
This command will give full access rights (read - modify and write) to all "Administrator" users for all the files in the site-packages
folder, and all the files in its subfolders. While this command executes, you should get the following messages:
...
processed file: C:\..\Anaconda\Lib\site-packages\__pycache__\readline.cpython-35.pyc
processed file: C:\..\Anaconda\Lib\site-packages\__pycache__\simplegeneric.cpython-35.pyc
processed file: C:\..\Anaconda\Lib\site-packages\__pycache__\six.cpython-35.pyc
processed file: C:\..\Anaconda\Lib\site-packages\__pycache__\test_path.cpython-35.pyc
processed file: C:\..\Anaconda\Lib\site-packages\__pycache__\test_pycosat.cpython-35.pyc
...
Successfully processed 38589 files; Failed processing 0 files
Now you can repeat STEP 2, and it should work!
Upvotes: 1
Reputation: 1001
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_()
Upvotes: 2