hello,
I have a textctrl with a wx.TE_PROCESS_ENTER style. I would like the OnEnter function to be called not only when the user press enter but also when the textctrl looses focus (e.g.: the user has clicked in another textctrl). How can I achieve this?
I’ve tried this but it doesn’t work (and it seems to freeze the GUI somehow):
def OnKillFocus(self, evt):
self.log.WriteText('OnKillFocus\n')
kType = wx.EVT_KEY_DOWN.typeId
ke=wx.KeyEvent(kType)
ke.SetUnicodeKey(wx.WXK_RETURN)
ke.SetEventObject( self.tc1 )
ke.SetId( self.tc1.GetId() )
self.tc1.EmulateKeyPress(ke)
evt.Skip()
To play around I’ve tried using this method with textctrl demo (enabling t1.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus), adding wx.TE_PROCESS_ENTER to t1 and replacing wx.WXK_RETURN with wx.WXK_SPACE to see something but nothing happens and I cannot select the text in self.tc1 anymore after t1 has lost focus
any suggestion?
thanks, Marco
you could just call the TE_PROCESS_ENTER method directly from your OnKillFocus method. If you’re using event.GetKeyCode() in the TE_PROCESS_ENTER handler, then you need to define a ‘fake’ GetKeyCode function in OnKillFocus, something like:
def OnKillFocus(self, evt):
def _GetKeyCode():
return wx.WXK_RETURN
fakeEvent = ''
fakeEvent.GetKeyCode = _GetKeyCode
self.YourProcessEnterMethod(fakeEvent)
···
On Monday, September 8, 2014 9:13:17 AM UTC-7, Marco Prosperi wrote:
hello,
I have a textctrl with a wx.TE_PROCESS_ENTER style. I would like the OnEnter function to be called not only when the user press enter but also when the textctrl looses focus (e.g.: the user has clicked in another textctrl). How can I achieve this?
I’ve tried this but it doesn’t work (and it seems to freeze the GUI somehow):
def OnKillFocus(self, evt):
self.log.WriteText('OnKillFocus\n')
kType = wx.EVT_KEY_DOWN.typeId
ke=wx.KeyEvent(kType)
ke.SetUnicodeKey(wx.WXK_RETURN)
ke.SetEventObject( self.tc1 )
ke.SetId( self.tc1.GetId() )
self.tc1.EmulateKeyPress(ke)
evt.Skip()
To play around I’ve tried using this method with textctrl demo (enabling t1.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus), adding wx.TE_PROCESS_ENTER to t1 and replacing wx.WXK_RETURN with wx.WXK_SPACE to see something but nothing happens and I cannot select the text in self.tc1 anymore after t1 has lost focus
any suggestion?
thanks, Marco