2006-12-11 06:19:27 +00:00
|
|
|
|
|
|
|
import wx
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TestPanel(wx.Panel):
|
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
|
|
|
wx.Panel.__init__(self, parent, -1, style=0)
|
|
|
|
|
|
|
|
# Create controls
|
|
|
|
sb = wx.StaticBox(self, -1, "Options")
|
|
|
|
searchBtnOpt = wx.CheckBox(self, -1, "Search button")
|
|
|
|
searchBtnOpt.SetValue(True)
|
|
|
|
cancelBtnOpt = wx.CheckBox(self, -1, "Cancel button")
|
|
|
|
menuBtnOpt = wx.CheckBox(self, -1, "Search menu")
|
|
|
|
|
|
|
|
self.search = wx.SearchCtrl(self, size=(200,-1), style=wx.TE_PROCESS_ENTER)
|
|
|
|
|
|
|
|
# Setup the layout
|
|
|
|
box = wx.StaticBoxSizer(sb, wx.VERTICAL)
|
|
|
|
box.Add(searchBtnOpt, 0, wx.ALL, 5)
|
|
|
|
box.Add(cancelBtnOpt, 0, wx.ALL, 5)
|
|
|
|
box.Add(menuBtnOpt, 0, wx.ALL, 5)
|
|
|
|
|
|
|
|
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
|
|
sizer.Add(box, 0, wx.ALL, 15)
|
|
|
|
sizer.Add((15,15))
|
|
|
|
sizer.Add(self.search, 0, wx.ALL, 15)
|
|
|
|
|
2006-12-11 21:26:58 +00:00
|
|
|
## self.tc = wx.TextCtrl(self) # just for testing that heights match...
|
|
|
|
## sizer.Add(self.tc, 0, wx.TOP, 15)
|
2006-12-11 06:19:27 +00:00
|
|
|
|
|
|
|
self.SetSizer(sizer)
|
|
|
|
|
|
|
|
|
|
|
|
# Set event bindings
|
|
|
|
self.Bind(wx.EVT_CHECKBOX, self.OnToggleSearchButton, searchBtnOpt)
|
|
|
|
self.Bind(wx.EVT_CHECKBOX, self.OnToggleCancelButton, cancelBtnOpt)
|
|
|
|
self.Bind(wx.EVT_CHECKBOX, self.OnToggleSearchMenu, menuBtnOpt)
|
|
|
|
|
2006-12-11 20:32:16 +00:00
|
|
|
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.OnSearch, self.search)
|
|
|
|
self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.OnCancel, self.search)
|
2007-02-07 16:24:56 +00:00
|
|
|
self.Bind(wx.EVT_TEXT_ENTER, self.OnDoSearch, self.search)
|
|
|
|
##self.Bind(wx.EVT_TEXT, self.OnDoSearch, self.search)
|
|
|
|
|
2006-12-11 06:19:27 +00:00
|
|
|
|
|
|
|
def OnToggleSearchButton(self, evt):
|
2006-12-11 16:34:36 +00:00
|
|
|
self.search.ShowSearchButton( evt.GetInt() )
|
2006-12-11 06:19:27 +00:00
|
|
|
|
|
|
|
def OnToggleCancelButton(self, evt):
|
2006-12-11 16:34:36 +00:00
|
|
|
self.search.ShowCancelButton( evt.GetInt() )
|
2006-12-11 06:19:27 +00:00
|
|
|
|
|
|
|
def OnToggleSearchMenu(self, evt):
|
|
|
|
if evt.GetInt():
|
|
|
|
self.search.SetMenu( self.MakeMenu() )
|
|
|
|
else:
|
|
|
|
self.search.SetMenu(None)
|
|
|
|
|
|
|
|
|
|
|
|
def OnSearch(self, evt):
|
|
|
|
self.log.write("OnSearch")
|
|
|
|
|
|
|
|
def OnCancel(self, evt):
|
|
|
|
self.log.write("OnCancel")
|
|
|
|
|
|
|
|
def OnDoSearch(self, evt):
|
|
|
|
self.log.write("OnDoSearch: " + self.search.GetValue())
|
|
|
|
|
|
|
|
|
|
|
|
def MakeMenu(self):
|
|
|
|
menu = wx.Menu()
|
|
|
|
item = menu.Append(-1, "Recent Searches")
|
|
|
|
item.Enable(False)
|
|
|
|
for txt in [ "You can maintain",
|
|
|
|
"a list of old",
|
|
|
|
"search strings here",
|
|
|
|
"and bind EVT_MENU to",
|
|
|
|
"catch their selections" ]:
|
|
|
|
menu.Append(-1, txt)
|
|
|
|
return menu
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
|
|
|
<h2><center>wx.SearchCtrl</center></h2>
|
|
|
|
|
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
|
|
|
|