]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/SearchCtrl.py
4 #----------------------------------------------------------------------
6 class TestPanel(wx
.Panel
):
7 def __init__(self
, parent
, log
):
9 wx
.Panel
.__init
__(self
, parent
, -1, style
=0)
12 sb
= wx
.StaticBox(self
, -1, "Options")
13 searchBtnOpt
= wx
.CheckBox(self
, -1, "Search button")
14 searchBtnOpt
.SetValue(True)
15 cancelBtnOpt
= wx
.CheckBox(self
, -1, "Cancel button")
16 menuBtnOpt
= wx
.CheckBox(self
, -1, "Search menu")
18 self
.search
= wx
.SearchCtrl(self
, size
=(200,-1), style
=wx
.TE_PROCESS_ENTER
)
21 box
= wx
.StaticBoxSizer(sb
, wx
.VERTICAL
)
22 box
.Add(searchBtnOpt
, 0, wx
.ALL
, 5)
23 box
.Add(cancelBtnOpt
, 0, wx
.ALL
, 5)
24 box
.Add(menuBtnOpt
, 0, wx
.ALL
, 5)
26 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
27 sizer
.Add(box
, 0, wx
.ALL
, 15)
29 sizer
.Add(self
.search
, 0, wx
.ALL
, 15)
31 self
.tc
= wx
.TextCtrl(self
) # just for testing that heights match...
32 sizer
.Add(self
.tc
, 0, wx
.TOP
, 15)
38 self
.Bind(wx
.EVT_CHECKBOX
, self
.OnToggleSearchButton
, searchBtnOpt
)
39 self
.Bind(wx
.EVT_CHECKBOX
, self
.OnToggleCancelButton
, cancelBtnOpt
)
40 self
.Bind(wx
.EVT_CHECKBOX
, self
.OnToggleSearchMenu
, menuBtnOpt
)
42 self
.Bind(wx
.EVT_SEARCHCTRL_SEARCH
, self
.OnSearch
, self
.search
)
43 self
.Bind(wx
.EVT_SEARCHCTRL_CANCEL
, self
.OnCancel
, self
.search
)
44 self
.search
.Bind(wx
.EVT_TEXT_ENTER
, self
.OnDoSearch
) #, self.search)
47 def OnToggleSearchButton(self
, evt
):
48 self
.search
.SetSearchButtonVisible( evt
.GetInt() )
50 def OnToggleCancelButton(self
, evt
):
51 self
.search
.SetCancelButtonVisible( evt
.GetInt() )
53 def OnToggleSearchMenu(self
, evt
):
55 self
.search
.SetMenu( self
.MakeMenu() )
57 self
.search
.SetMenu(None)
60 def OnSearch(self
, evt
):
61 self
.log
.write("OnSearch")
63 def OnCancel(self
, evt
):
64 self
.log
.write("OnCancel")
66 def OnDoSearch(self
, evt
):
67 self
.log
.write("OnDoSearch: " + self
.search
.GetValue())
72 item
= menu
.Append(-1, "Recent Searches")
74 for txt
in [ "You can maintain",
76 "search strings here",
77 "and bind EVT_MENU to",
78 "catch their selections" ]:
83 #----------------------------------------------------------------------
85 def runTest(frame
, nb
, log
):
86 win
= TestPanel(nb
, log
)
89 #----------------------------------------------------------------------
93 overview
= """<html><body>
94 <h2><center>wx.SearchCtrl</center></h2>
101 if __name__
== '__main__':
104 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])