I've been searching the internet about the Syntax highlighting of a particular file in a text editor and i read about Lexers and Yacc. i'm quite confuse about the concepts on syntax highlighting.
I've created a simple text editor using PyQt4 and i want it to enable syntax highlighting of programming languages such as HTML,CSS,Python,C/C++. But i've no clue on how to start implementing this and where to start. Please someone point me to the right direction and pliz clear my doubts on syntax highlighting. please.
If you want to make your life easy, use QScintilla - it does everything you need and more straight out of the box.
QScintilla is included with the PyQt binary installers for Windows (which can be found here), and almost all Linux distros will have QScintilla packages in their repositories. Alternatively, the QScintilla source code can be found here.
And here's a minimal QScintilla example that shows how easy it is to get started:
import sys, os
from PyQt4 import QtGui, Qsci
class Window(Qsci.QsciScintilla):
def __init__(self):
Qsci.QsciScintilla.__init__(self)
self.setLexer(Qsci.QsciLexerPython(self))
self.setText(open(os.path.abspath(__file__)).read())
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = Window()
window.setGeometry(500, 300, 500, 500)
window.show()
sys.exit(app.exec_())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With