I have a problem to setup a custom lexer using in wx.stc.StyledTextCtrl (wxPython). I have a text file which consit of certain keywords which I would like to highlight. The text file is not related to any of the programing languages and so I cannot use the buildin lexers. The method I tried is slow and I was just wondering if someone knows a better way. Here is my code:
First, I create a custom lexer and then bind wx.stc.EVT_STC_STYLENEEDED to the appropriate function for highlighting
self.text.SetLexer(wx.stc.STC_LEX_CONTAINER) self.text.SetStyleBits(5) self.text.Bind(wx.stc.EVT_STC_STYLENEEDED, self.Color)
than I create the actual function to handle the event:
def onColor1(self, event): styled_text=['BFG', 'FYI', 'DPS', 'DSD'] fulltext = self.text.GetText() self.text.StyleSetSpec(2, 'fore:#0000FF, back:#FFFFFF,face:Courier New,size:12') for item in styled_text: pos=fulltext.find(item) while pos!=-1: self.text.StartStyling(pos, 0xff) self.text.SetStyling(len(item), 2) pos = fulltext.find(item, pos+1)
this seems to work fine but it's very slow.
I appreciate any help
thanks in advance