TextCtrl.AutoComplete interraction with EVT_TEXT_ENTER flag

I don't understand how TextCtrl.AutoComplete interracts with
EVT_TEXT_ENTER flag. The following code

class ListTextCtrl(wx.TextCtrl):

def __init__(self, *args, **kwargs):
self.items = kwargs.pop('items', ) # default for items is empty list

wx.TextCtrl.__init__(self, *args, **kwargs)
self.AutoComplete(self.items)
self.Bind(wx.EVT_TEXT_ENTER,self.Skip)

def Skip(self, evt):
evt.Skip()### trying to get here

does not reach line with '### trying to get here', while the following code

class ListTextCtrl(wx.TextCtrl):

def __init__(self, *args, **kwargs):
self.items = kwargs.pop('items', ) # default for items is empty list

wx.TextCtrl.__init__(self, *args, **kwargs)
     ### self.AutoComplete(self.items) ## REMOVED
self.Bind(wx.EVT_TEXT_ENTER,self.Skip)

def Skip(self, evt):
evt.Skip()### trying to get here

reaches it fine.

Platform and version? Are you using the wx.TE_PROCESS_ENTER style flag?

Is there any way to use TextCtrl.AutoComplete, and EVT_TEXT_ENTER ?

It's not too surprising that an auto-complete feature would want to take the Enter key event for itself, although I haven't found anything that explicitly does that in the current implementation. (It could be doing it in the native code though.)

Some things you could try that may let you have first crack at the event before the auto-completer gets it:

1, Catch the EVT_KEY_DOWN event and see if there is an event for the Enter key there.

2. Create a class derived from wx.EvtHandler, and Bind a handler for EVT_TEXT_ENTER or EVT_KEY_DOWN there. Push an instance of that class on to your textctrl with PushEventHandler. Don't forget to Pop it later.

···

On 12/8/12 11:43 AM, Lou King wrote:

--
Robin Dunn
Software Craftsman

Thanks. Forgot to mention that it is wx 2.9.4 on windows 8, with python 2.7.3

So is this a bug or the way it’s supposed to work? I didn’t want my class to have to know what flags are used, figuring it would act like TextCtrl normally does. I think the suggestions you’re making assumes wx.TE_PROCESS_ENTER (which was, indeed used).

In the interim, I wrote my own class which does the autocomplete function, but I had expected TextCtrl.Autocomplete() to pass on the enter event.

I’ll play with it, especially your first suggestion, and report back.

···

On Monday, December 10, 2012 7:27:38 PM UTC-5, Robin Dunn wrote:

On 12/8/12 11:43 AM, Lou King wrote:

I don’t understand how TextCtrl.AutoComplete interracts with

EVT_TEXT_ENTER flag. The following code

class ListTextCtrl(wx.TextCtrl):

def init(self, *args, **kwargs):

self.items = kwargs.pop(‘items’, ) # default for items is empty list

wx.TextCtrl.init(self, *args, **kwargs)

self.AutoComplete(self.items)

self.Bind(wx.EVT_TEXT_ENTER,self.Skip)

def Skip(self, evt):

evt.Skip()### trying to get here

does not reach line with ‘### trying to get here’, while the following code

class ListTextCtrl(wx.TextCtrl):

def init(self, *args, **kwargs):

self.items = kwargs.pop(‘items’, ) # default for items is empty list

wx.TextCtrl.init(self, *args, **kwargs)

 ###        self.AutoComplete(self.items)    ## REMOVED

self.Bind(wx.EVT_TEXT_ENTER,self.Skip)

def Skip(self, evt):

evt.Skip()### trying to get here

reaches it fine.

Platform and version? Are you using the wx.TE_PROCESS_ENTER style flag?

Is there any way to use TextCtrl.AutoComplete, and EVT_TEXT_ENTER ?

It’s not too surprising that an auto-complete feature would want to take
the Enter key event for itself, although I haven’t found anything that
explicitly does that in the current implementation. (It could be doing
it in the native code though.)

Some things you could try that may let you have first crack at the event
before the auto-completer gets it:

1, Catch the EVT_KEY_DOWN event and see if there is an event for the
Enter key there.

  1. Create a class derived from wx.EvtHandler, and Bind a handler for
    EVT_TEXT_ENTER or EVT_KEY_DOWN there. Push an instance of that class on
    to your textctrl with PushEventHandler. Don’t forget to Pop it later.


Robin Dunn

Software Craftsman

http://wxPython.org

As can be seen by the enclosed example, AutoComplete() alters TextCtrl behavior as follows.

  1. with AutoComplete used, for Bind(wx.EVT_KEY_DOWN, OnKey), Bind(wx.TE_PROCESS_ENTER, OnEnter), carriage return is seen at OnKey, but enter is NOT seen at OnEnter
  2. with AutoComplete used, for Bind(wx.EVT_CHAR, OnKey), Bind(wx.TE_PROCESS_ENTER, OnEnter), carriage return is NOT seen at OnKey, and enter is NOT seen at OnEnter
  3. with no AutoComplete, for either Bind(wx.EVT_KEY_DOWN, OnKey) or Bind(wx.EVT_CHAR, OnKey), and Bind(wx.TE_PROCESS_ENTER, OnEnter), carriage return is seen at OnKey, and enter is seen at OnEnter

seems to me like a bug in AutoComplete. I am guessing the bug is in wxWidgets, not wxPython, but I don’t know c++ well enough to confirm.

Do you agree?

AutoTextCtrl.py (2.62 KB)

···

On Monday, December 10, 2012 8:38:35 PM UTC-5, Lou King wrote:

Thanks. Forgot to mention that it is wx 2.9.4 on windows 8, with python 2.7.3

So is this a bug or the way it’s supposed to work? I didn’t want my class to have to know what flags are used, figuring it would act like TextCtrl normally does. I think the suggestions you’re making assumes wx.TE_PROCESS_ENTER (which was, indeed used).

In the interim, I wrote my own class which does the autocomplete function, but I had expected TextCtrl.Autocomplete() to pass on the enter event.

I’ll play with it, especially your first suggestion, and report back.

On Monday, December 10, 2012 7:27:38 PM UTC-5, Robin Dunn wrote:

On 12/8/12 11:43 AM, Lou King wrote:

I don’t understand how TextCtrl.AutoComplete interracts with

EVT_TEXT_ENTER flag. The following code

class ListTextCtrl(wx.TextCtrl):

def init(self, *args, **kwargs):

self.items = kwargs.pop(‘items’, ) # default for items is empty list

wx.TextCtrl.init(self, *args, **kwargs)

self.AutoComplete(self.items)

self.Bind(wx.EVT_TEXT_ENTER,self.Skip)

def Skip(self, evt):

evt.Skip()### trying to get here

does not reach line with ‘### trying to get here’, while the following code

class ListTextCtrl(wx.TextCtrl):

def init(self, *args, **kwargs):

self.items = kwargs.pop(‘items’, ) # default for items is empty list

wx.TextCtrl.init(self, *args, **kwargs)

 ###        self.AutoComplete(self.items)    ## REMOVED

self.Bind(wx.EVT_TEXT_ENTER,self.Skip)

def Skip(self, evt):

evt.Skip()### trying to get here

reaches it fine.

Platform and version? Are you using the wx.TE_PROCESS_ENTER style flag?

Is there any way to use TextCtrl.AutoComplete, and EVT_TEXT_ENTER ?

It’s not too surprising that an auto-complete feature would want to take
the Enter key event for itself, although I haven’t found anything that
explicitly does that in the current implementation. (It could be doing
it in the native code though.)

Some things you could try that may let you have first crack at the event
before the auto-completer gets it:

1, Catch the EVT_KEY_DOWN event and see if there is an event for the
Enter key there.

  1. Create a class derived from wx.EvtHandler, and Bind a handler for
    EVT_TEXT_ENTER or EVT_KEY_DOWN there. Push an instance of that class on
    to your textctrl with PushEventHandler. Don’t forget to Pop it later.


Robin Dunn

Software Craftsman

http://wxPython.org

Sorry, wherever I said wx.TE_PROCESS_ENTER below, I meant wx.EVT_TEXT_ENTER. Code was correct, only my typing was misleading.

···

On Tuesday, December 11, 2012 8:00:59 AM UTC-5, Lou King wrote:

As can be seen by the enclosed example, AutoComplete() alters TextCtrl behavior as follows.

  1. with AutoComplete used, for Bind(wx.EVT_KEY_DOWN, OnKey), Bind(wx.TE_PROCESS_ENTER, OnEnter), carriage return is seen at OnKey, but enter is NOT seen at OnEnter
  2. with AutoComplete used, for Bind(wx.EVT_CHAR, OnKey), Bind(wx.TE_PROCESS_ENTER, OnEnter), carriage return is NOT seen at OnKey, and enter is NOT seen at OnEnter
  3. with no AutoComplete, for either Bind(wx.EVT_KEY_DOWN, OnKey) or Bind(wx.EVT_CHAR, OnKey), and Bind(wx.TE_PROCESS_ENTER, OnEnter), carriage return is seen at OnKey, and enter is seen at OnEnter

seems to me like a bug in AutoComplete. I am guessing the bug is in wxWidgets, not wxPython, but I don’t know c++ well enough to confirm.

Do you agree?

On Monday, December 10, 2012 8:38:35 PM UTC-5, Lou King wrote:

Thanks. Forgot to mention that it is wx 2.9.4 on windows 8, with python 2.7.3

So is this a bug or the way it’s supposed to work? I didn’t want my class to have to know what flags are used, figuring it would act like TextCtrl normally does. I think the suggestions you’re making assumes wx.TE_PROCESS_ENTER (which was, indeed used).

In the interim, I wrote my own class which does the autocomplete function, but I had expected TextCtrl.Autocomplete() to pass on the enter event.

I’ll play with it, especially your first suggestion, and report back.

On Monday, December 10, 2012 7:27:38 PM UTC-5, Robin Dunn wrote:

On 12/8/12 11:43 AM, Lou King wrote:

I don’t understand how TextCtrl.AutoComplete interracts with

EVT_TEXT_ENTER flag. The following code

class ListTextCtrl(wx.TextCtrl):

def init(self, *args, **kwargs):

self.items = kwargs.pop(‘items’, ) # default for items is empty list

wx.TextCtrl.init(self, *args, **kwargs)

self.AutoComplete(self.items)

self.Bind(wx.EVT_TEXT_ENTER,self.Skip)

def Skip(self, evt):

evt.Skip()### trying to get here

does not reach line with ‘### trying to get here’, while the following code

class ListTextCtrl(wx.TextCtrl):

def init(self, *args, **kwargs):

self.items = kwargs.pop(‘items’, ) # default for items is empty list

wx.TextCtrl.init(self, *args, **kwargs)

 ###        self.AutoComplete(self.items)    ## REMOVED

self.Bind(wx.EVT_TEXT_ENTER,self.Skip)

def Skip(self, evt):

evt.Skip()### trying to get here

reaches it fine.

Platform and version? Are you using the wx.TE_PROCESS_ENTER style flag?

Is there any way to use TextCtrl.AutoComplete, and EVT_TEXT_ENTER ?

It’s not too surprising that an auto-complete feature would want to take
the Enter key event for itself, although I haven’t found anything that
explicitly does that in the current implementation. (It could be doing
it in the native code though.)

Some things you could try that may let you have first crack at the event
before the auto-completer gets it:

1, Catch the EVT_KEY_DOWN event and see if there is an event for the
Enter key there.

  1. Create a class derived from wx.EvtHandler, and Bind a handler for
    EVT_TEXT_ENTER or EVT_KEY_DOWN there. Push an instance of that class on
    to your textctrl with PushEventHandler. Don’t forget to Pop it later.


Robin Dunn

Software Craftsman

http://wxPython.org

I can't say for sure as I didn't implement it and I have not really used the feature yet myself. It may be dependent on the platform too. If it is a bug then it is a wxWidgets bug because wxPython doesn't do anything that would affect this.

···

On 12/11/12 5:00 AM, Lou King wrote:

As can be seen by the enclosed example, AutoComplete() alters TextCtrl
behavior as follows.

1. with AutoComplete used, for Bind(wx.EVT_KEY_DOWN, OnKey),
    Bind(wx.TE_PROCESS_ENTER, OnEnter), carriage return is seen at
    OnKey, but enter is NOT seen at OnEnter
2. with AutoComplete used, for Bind(wx.EVT_CHAR, OnKey),
    Bind(wx.TE_PROCESS_ENTER, OnEnter), carriage return is NOT seen at
    OnKey, and enter is NOT seen at OnEnter
3. with no AutoComplete, for either Bind(wx.EVT_KEY_DOWN, OnKey)
    or Bind(wx.EVT_CHAR, OnKey), and Bind(wx.TE_PROCESS_ENTER, OnEnter),
    carriage return is seen at OnKey, and enter is seen at OnEnter

seems to me like a bug in AutoComplete. I am guessing the bug is in
wxWidgets, not wxPython, but I don't know c++ well enough to confirm.

Do you agree?

--
Robin Dunn
Software Craftsman