954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

wxPython key down evt problem

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

WolfShield
Posting Whiz in Training
236 posts since Oct 2010
Reputation Points: 28
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: