SearchCtrl - Cannot bind to pressing enter event

Hi,

I’m trying to use a SearchCtrl widget on OS X as in the example below. On pressing enter, nothing happens. However, if I replace wx.SearchCtrl with wx.TextCtrl, “You pressed enter!” is printed as expected…

Output from wx.version() = 2.9.2.4 osx-cocoa (classic)

I’ve read through all the documentation I can find… initially I was missing the style=wx.TE_PROCESS_ENTER, which fixed things for the TextCtrl, but I can’t find anything more for the SearchCtrl, they appear to be near identical widgets!

Any help would be VERY much appreciated!

Thanks!

Dan

···

######################################################################

#!/usr/bin/python

-- coding: iso-8859-1 --

try:

import wx

wx.

except ImportError:

raise ImportError,“The wxPython module is required to run this program”

class simpleapp_wx(wx.Frame):

def init(self,parent,id,title):

wx.Frame.init(self,parent,id,title)

self.parent = parent

self.initialize()

def initialize(self):

self.entry = wx.SearchCtrl(self,-1,value=u"Enter text here.",style=wx.TE_PROCESS_ENTER)

self.Bind(wx.EVT_TEXT_ENTER, self.OnPressEnter, self.entry)

self.Show(True)

def OnPressEnter(self,event):

print “You pressed enter !”

if name == “main”:

app = wx.App()

frame = simpleapp_wx(None,-1,‘my application’)

app.MainLoop()

I've read through all the documentation I can find... initially I was
missing the style=wx.TE_PROCESS_ENTER, which fixed things for the TextCtrl,
but I can't find anything more for the SearchCtrl, they appear to be near
identical widgets!

And they are indeed!

From pydoc wx.SearchCtrl:
> Since the control derives from `wx.TextCtrl` it is convenient to
> use the styles and events designed for `wx.TextCtrl`. For example you can
> use the ``wx.TE_PROCESS_ENTER`` style and catch the
> ``wx.EVT_TEXT_ENTER`` event to know when the user has pressed the
> Enter key in the control and wishes to start a search.

I don't understand exactly what you mean; if it is about the event
from the search button, you'll find it attached (wx 2.8.12.1-5).

The event for the Cancel button has the same syntax.

searchCtrl.py (1.63 KB)

···

On Sat, 17 Dec 2011 09:27:20 +0000 Dan Bishop <dan@danbishop.org> wrote:

--
"Maybe we can get together and show off to each other sometimes."

Thank you!

I just tried your code and when I press enter, I get: SearchCtrl
SEARCH_BTN clicked

Pressing enter is being interpreted as pressing the search button!
Presumably this is a bug in my version of wxpython?

For the time being, I'll just bind to the search button event as well.

···

On Dec 17, 7:21 pm, "Jean-Yves F. Barbier" <12u...@gmail.com> wrote:

On Sat, 17 Dec 2011 09:27:20 +0000 > > Dan Bishop <d...@danbishop.org> wrote:

> I've read through all the documentation I can find... initially I was
> missing the style=wx.TE_PROCESS_ENTER, which fixed things for the TextCtrl,
> but I can't find anything more for the SearchCtrl, they appear to be near
> identical widgets!

And they are indeed!

From pydoc wx.SearchCtrl:
> Since the control derives from `wx.TextCtrl` it is convenient to
> use the styles and events designed for `wx.TextCtrl`. For example you can
> use the ``wx.TE_PROCESS_ENTER`` style and catch the
> ``wx.EVT_TEXT_ENTER`` event to know when the user has pressed the
> Enter key in the control and wishes to start a search.

I don't understand exactly what you mean; if it is about the event
from the search button, you'll find it attached (wx 2.8.12.1-5).

The event for the Cancel button has the same syntax.

--
"Maybe we can get together and show off to each other sometimes."

searchCtrl.py
1KViewDownload

I just tried your code and when I press enter, I get: SearchCtrl
SEARCH_BTN clicked

Pressing enter is being interpreted as pressing the search button!
Presumably this is a bug in my version of wxpython?

Let clear that: if it happens after you've clicked into SC and
eventually typed some text, then hit CR, yes it's a bug (remember
2.9 is a DEV version in ALPHA state!).

For the time being, I'll just bind to the search button event as well.

Don't: create the 2 methods and for the time being call the second
one from the first one; or leave the unused method with just a
print (print ("mymethod from myclass: WASN'T WORKING AS OF
20111218") and "event.Skip()" inside.
This way the day it change you won't forget, get mad and throw your
pizza, wife, kids, beer or coffee on the wall :wink: (hold the beer:
throw the wife!)

···

On Sun, 18 Dec 2011 05:44:13 -0800 (PST) Dan Bishop <dan@danbishop.org> wrote:

--
Hear about...
  the San Franciscan who backed off the bus because he thought
  someone would grab his seat?