Styling text in StyledTextCtrl
The StyledTextCtrl
class is an advanced text-editing component provided by the wx.stc
module. This class is a wx
wrapper around the Scintilla code editor control. This control is primarily geared toward editing source code files. It provides a large set of features for enhanced code-editing support. In this recipe, we will look at how to set up syntax highlighting for Python source code files using StyledTextCtrl
.
How to do it…
Perform the following steps:
This recipe will be split into two classes. Starting here with a base class to set up some programming language-independent settings on
StyledTextCtrl
. Take a look at the following code:import wx import wx.stc as stc import keyword class CodeEditorBase(stc.StyledTextCtrl): def __init__(self, parent): super(CodeEditorBase, self).__init__(parent) # Attributes font = wx.Font(10, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL...