As discussed in the StyledTextCtrl using lexers section of Chapter 4, Advanced Building Blocks of a User Interface, the StyledTextCtrl
is a powerful source code editing component that has support for syntax-highlighting many different types of source code. However, if you find that you need to support some highlighting in your application that the
StyledTextCtrl
doesn't have a built-in lexer for, you might think that you are out of luck. This isn't the case, though. Custom lexers can be added through the use of the special container lexer. This recipe shows how to write and use a custom lexer that does some simple highlighting.
As a part of this recipe, we will create a simple little framework that can be extended to do other kinds of highlighting. Let's start with the BaseLexer
class, which defines a single method interface for handling the EVT_STC_STYLENEEDED
event that is generated by the StyledTextCtrl
:
import wx import wx.stc class BaseLexer...