Discussion:
textctrl and kill focus
Marco Prosperi
2014-09-08 16:13:17 UTC
Permalink
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 received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-08 16:47:22 UTC
Permalink
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)
Post by Marco Prosperi
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
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 received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marco Prosperi
2014-09-09 21:18:32 UTC
Permalink
thank you, it's ok now
Post by Nathan McCorkle
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
return wx.WXK_RETURN
fakeEvent = ''
fakeEvent.GetKeyCode = _GetKeyCode
self.YourProcessEnterMethod(fakeEvent)
Post by Marco Prosperi
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
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 received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...