WolfShield 32 Posting Whiz in Training

I have a wxPython project that I want to add a syntax highlighting feature to the RichTextCtrl.

I have the function and the binding, but it doesn't format the words when I type. If I bind the function to a menu item it works just fine.

I am using "this" just to test it.

Binding:

self.Bind(wx.EVT_CHAR_HOOK, self.FormatWord)

Function:

def FormatWord(self, e):
        # Check word being written against some keywords and mark with a style.
        if(e.GetKeyCode() == wx.WXK_DOWN):
            myWordS = self.control.GetValue().split(" ")
            self.control.Clear()
            for word in myWordS:
                if word == "this":
                    self.control.BeginBold()
                    self.control.BeginTextColour('blue')
                    self.control.WriteText(word)
                    self.control.EndTextColour()
                    self.control.EndBold()
                    self.control.WriteText(" ")
                else:
                    self.control.WriteText(word)
                    self.control.WriteText(" ")
        else:
            e.Skip()

Thanks in advance,

- WolfShield

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.