I have a wxTextCtrl which should usually accept text input from the user, but where certain keypresses should instead generate other events. Which event type do I need for this, and how do I ensure that no text is appended to the text control for that keystroke?
if key == WXK_RETURN: # or whatever
self.dosomestuff()
else:
evt.Skip()
···
On Wed, 2003-12-10 at 15:48, Ben Sizer wrote:
I have a wxTextCtrl which should usually accept text input from the
user, but where certain keypresses should instead generate other events.
Which event type do I need for this, and how do I ensure that no text
is appended to the text control for that keystroke?
--
Thys Meintjes
BEng Electronic (UP), MEng Bio (UP)
Intrepid Investigator of Interesting Things
+27 82 3764 602
I have a wxTextCtrl which should usually accept text input from the user, but where certain keypresses should instead generate other events. Which event type do I need for this, and how do I ensure that no text is appended to the text control for that keystroke?
Here is one way. It is in the demo.
class MyValidator(wxPyValidator):
def __init__(self, flag=None, pyVar=None):
wxPyValidator.__init__(self)
self.flag = flag
EVT_CHAR(self, self.OnChar)
def Clone(self):
return MyValidator(self.flag)
def Validate(self):
object = self.GetWindow()
objectname = object.GetName()
if objectname == 'textctrl':
val = object.GetValue()
return val
def OnChar(self, event):
key = event.KeyCode()
if self.flag == 'SEX' and chr(key) in 'MFmf':
self.dosomething()
return
return
Use the validator with the appropriate flag for your TextCtrl