Creating a syntax highlighter in python(PyQt4)
Question: 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.


Answer: If you want to make your life easy, use
[QScintilla](http://pyqt.sourceforge.net/Docs/QScintilla2/) \- 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](http://www.riverbankcomputing.com/software/pyqt/download)),
and almost all Linux distros will have QScintilla packages in their
repositories. Alternatively, the QScintilla source code can be found
[here](http://www.riverbankcomputing.com/software/qscintilla/download).

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_())
    

