wxSearchCtrl and mouse down problem

I am trying to use wxSearchCtrl such that clicking in it will clear
the initially placed value, but having a problem…

The problem is that the mouse LeftDown event only works if you
click in a precise place in the SearchCtrl, which is just to the right of
the bitmap. This isn’t the case in a TextCtrl, in which you click
anywhere and it will generate the mouse down event.

I have attached a runnable sample that shows this difference. I am
not sure what the issue is, though I imagine it has something to do
with the control’s built-in showing of the word “search” as a default…
or something like that. But I would like the SearchCtrl to be able
to be clicked anywhere in it and have that generate the event and thus
clear it.

Any help is appreciated. Runnable sample follows:

···

#---------------------------------------------------------------------------------
#Boa:Frame:Frame1

import wx

def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1SEARCHCTRL1,
wxID_FRAME1STATICTEXT1, wxID_FRAME1STATICTEXT2, wxID_FRAME1TEXTCTRL1,
] = [wx.NewId() for _init_ctrls in range(6)]

class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don’t edit
wx.Frame.init(self, id=wxID_FRAME1, name=’’, parent=prnt,
pos=wx.Point(298, 205), size=wx.Size(344, 164),
style=wx.DEFAULT_FRAME_STYLE, title=‘Frame1’)
self.SetClientSize(wx.Size(336, 130))

    self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
          pos=wx.Point(0, 0), size=wx.Size(336, 130),
          style=wx.TAB_TRAVERSAL)

    self.searchCtrl1 = wx.SearchCtrl(id=wxID_FRAME1SEARCHCTRL1,
          name='searchCtrl1', parent=self.panel1, pos=wx.Point(16, 88),
          size=wx.Size(296, 21), style=0,
          value=u'this only works if you click just to the right of the bitmap')
    self.searchCtrl1.Bind(wx.EVT_LEFT_DOWN, self.OnSearchCtrl1LeftDown)

    self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
          parent=self.panel1, pos=wx.Point(16, 32), size=wx.Size(299, 21),
          style=0, value=u'try to clear this by clicking in it anywhere')
    self.textCtrl1.Bind(wx.EVT_LEFT_DOWN, self.OnTextCtrl1LeftDown)

    self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
          label=u'A SearcCtrl--difficulty clearing unless...',
          name='staticText1', parent=self.panel1, pos=wx.Point(16, 72),
          size=wx.Size(189, 13), style=0)

    self.staticText2 = wx.StaticText(id=wxID_FRAME1STATICTEXT2,
          label=u'A TextCtrl--can clear by clicking anywhere',
          name='staticText2', parent=self.panel1, pos=wx.Point(16, 16),
          size=wx.Size(203, 13), style=0)

def __init__(self, parent):
    self._init_ctrls(parent)
    #self.searchCtrl1.ShowSearchButton(False)

def OnSearchCtrl1LeftDown(self, event):
    self.searchCtrl1.Clear()

def OnTextCtrl1LeftDown(self, event):
    self.textCtrl1.Clear()

if name == ‘main’:
app = wx.PySimpleApp()
frame = create(None)
frame.Show()

app.MainLoop()

Hi,

···

-----Original Message-----
From: C M [mailto:cmpython@gmail.com]
Sent: Sunday, March 16, 2008 8:28 PM
To: wxPython-users@lists.wxwidgets.org
Subject: wxSearchCtrl and mouse down problem

I am trying to use wxSearchCtrl such that clicking in it will
clear the initially placed value, but having a problem...

The problem is that the mouse LeftDown event only works if
you click in a precise place in the SearchCtrl, which is just
to the right of the bitmap. This isn't the case in a
TextCtrl, in which you click anywhere and it will generate
the mouse down event.

I have attached a runnable sample that shows this difference.
I am not sure what the issue is, though I imagine it has
something to do with the control's built-in showing of the
word "search" as a default...
or something like that. But I would like the SearchCtrl to
be able to be clicked *anywhere* in it and have that generate
the event and thus clear it.

Any help is appreciated. Runnable sample follows:

#-------------------------------------------------------------
--------------------
#Boa:Frame:Frame1

        self.searchCtrl1 = wx.SearchCtrl(id=wxID_FRAME1SEARCHCTRL1,
              name='searchCtrl1', parent=self.panel1,
pos=wx.Point(16, 88),
              size=wx.Size(296, 21), style=0,
              value=u'this only works if you click just to
the right of the bitmap')
        self.searchCtrl1.Bind(wx.EVT_LEFT_DOWN,
self.OnSearchCtrl1LeftDown)

I'm not sure why this doesn't work, but since the search control is based
on the TextCtrl, I'd bind to the EVT_SET_FOCUS. I've done this with
TextCtrls that I've needed cleared when clicked and it worked for me.

Mike