0

I have a wxTextCtrl and I have the cursor move 4 spaces on tab key down. But if I have not typed anything the cursor does not move nor does text when I press tab.

self.editor = wx.TextCtrl(splitter, style = wx.TE_MULTILINE)
wx.EVT_KEY_DOWN(self.editor, self.on_key_down)

def on_key_down(self, e):
    if e.GetKeyCode() == wx.WXK.TAB:
        current = self.editor.GetInsertionPoint()
        tab = current + 4
        self.editor.SetInsertionPoint(tab)
    else:
        e.Skip()

If anyone could help me with getting the cursor to move even if I've not typed anything in front of the cursor and any text in front of the cursor.

Also I would like to get certain key words to change colour when typed. If anyone could help with that I would be very appreciative.

SC7639
  • 94
  • 1
  • 10

1 Answers1

2

Try using WriteText:

def on_key_down(self, e):
    if e.GetKeyCode() == wx.WXK_TAB:
        tab = ' ' * 4
        self.editor.WriteText(tab)
    else:
        e.Skip()
joaquin
  • 82,968
  • 29
  • 138
  • 152
  • Brilliant if I didn't know about the write text XD. Do you know anything about colouring certain words? – SC7639 May 02 '12 at 23:13
  • I could imagine you could save your keystrokes in a list (that is refreshed after every non alphabetical key) and check whether you entered a word from a list of words. If the word is in the list, you delete the already written chars and rewrite it again with a selected color. – joaquin May 03 '12 at 13:46
  • That's the kind of thing i was thinking. Also how could i get it go back 4 spaces on SHIFT + TAB buttons pressed. I have tried but can't work out how to get if e.GetKeyCode() == wx.WXK_TAB and wx.WXK_SHIFT to work, I've tried a few different ways and it wont work – SC7639 May 04 '12 at 15:47