1

I have been working on a simple textctrl project to get more acquainted with wxpython and I have hit a small road block. I am making a simple code editor, and I am currently working on the syntax highlighting. Everything works fine except because I have my textctrl bound to an event:

self.status_area.Bind(wx.EVT_CHAR, self.onKeyPress)

and I have code in that definition:

def onKeyPress (self, event):
    Line = self.status_area.GetValue()

It will no longer allow the user to type in any letters. I am able to delete and create a new line without any problem, but if I type "hello" nothing will show up. When debugging my code I know its running through onKeyPress() and the code inside and if I change the code to:

def onKeyPress (self, event):
    event.Skip()

it will work fine. I tried to recode the normal text editor workings into the onKeyPress() but it began to get too bulky. Any help on the matter would be greatly appreciated.

drfrev
  • 35
  • 2
  • 7
  • That fixed the problem I had, thank you so much. This is a really good forum. I didn't need to add the event.skip() though. – drfrev Aug 17 '11 at 19:12
  • 1
    Don't forget to accept an answer if it fixed your problem. You can do that by clicking on the check-mark next to the answer. – Bogdan Aug 18 '11 at 10:13
  • what fixed the problem, i cant see anything :( –  Jan 05 '13 at 17:16

2 Answers2

2

to creat textctrl

self.text_ctrl = wx.TextCtrl(self.panel_1, -1, "some thing", style=wx.TE_MULTILINE | wx.TE_RICH2 )

to bind

self.Bind(wx.EVT_TEXT, self.ON_Write, self.text_ctrl)

now the definition:

def ON_Write(self, event):
   line = self.text_ctrl.Value
user2229472
  • 509
  • 3
  • 10
2

Try EVT_TEXT rather than EVT_CHAR. In my solution, I added it AFTER event.Skip()

chow
  • 484
  • 2
  • 8
  • 21
  • It doesn't matter where you call `event.Skip()` in an event handler, as long as you call it if necessary. – FogleBird Aug 18 '11 at 16:12