Implementing highlighting in StyledTextCtrl
The StyledTextCtrl
provides a vast number of built-in lexers to provide syntax highlighting of various types of programming languages. Its API also allows us to extend these capabilities by providing our own custom styling of text in the buffer. This can be useful to create a text editor for your own custom markup or for special text formatting. In this recipe, we will take a look at how to implement custom text styling in StyledTextCtrl
.
Getting ready
If you haven't already, you may want to jump back and take a look at the other StyledTextCtrl
recipes in Chapter 4, Containers and Advanced Controls, to get some familiarity with StyledTextCtrl
prior to continuing with this recipe.
How to do it…
Here are the steps for this recipe:
First, we need to import the
wx.stc
submodule and define a couple of IDs to use for our custom lexer's different styles, as follows:import wx import wx.stc as stc # Style IDs for the KeywordLexer STC_STYLE_KW_DEFAULT, \ STC_STYLE_KW_KEYWORD...