]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/SearchCtrl.py
Add parent parameter to BusyInfo
[wxWidgets.git] / wxPython / demo / SearchCtrl.py
CommitLineData
3f7f284d
RD
1
2import wx
3
4#----------------------------------------------------------------------
5
6class TestPanel(wx.Panel):
7 def __init__(self, parent, log):
8 self.log = log
9 wx.Panel.__init__(self, parent, -1, style=0)
10
11 # Create controls
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")
17
18 self.search = wx.SearchCtrl(self, size=(200,-1), style=wx.TE_PROCESS_ENTER)
19
20 # Setup the layout
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)
25
26 sizer = wx.BoxSizer(wx.HORIZONTAL)
27 sizer.Add(box, 0, wx.ALL, 15)
28 sizer.Add((15,15))
29 sizer.Add(self.search, 0, wx.ALL, 15)
30
c33c11fa
RD
31## self.tc = wx.TextCtrl(self) # just for testing that heights match...
32## sizer.Add(self.tc, 0, wx.TOP, 15)
3f7f284d
RD
33
34 self.SetSizer(sizer)
35
36
37 # Set event bindings
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)
41
c60122bf
KO
42 self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.OnSearch, self.search)
43 self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.OnCancel, self.search)
c33c11fa 44 self.search.Bind(wx.EVT_TEXT_ENTER, self.OnDoSearch, self.search)
3f7f284d
RD
45
46
47 def OnToggleSearchButton(self, evt):
0a95d336 48 self.search.ShowSearchButton( evt.GetInt() )
3f7f284d
RD
49
50 def OnToggleCancelButton(self, evt):
0a95d336 51 self.search.ShowCancelButton( evt.GetInt() )
3f7f284d
RD
52
53 def OnToggleSearchMenu(self, evt):
54 if evt.GetInt():
55 self.search.SetMenu( self.MakeMenu() )
56 else:
57 self.search.SetMenu(None)
58
59
60 def OnSearch(self, evt):
61 self.log.write("OnSearch")
62
63 def OnCancel(self, evt):
64 self.log.write("OnCancel")
65
66 def OnDoSearch(self, evt):
67 self.log.write("OnDoSearch: " + self.search.GetValue())
68
69
70 def MakeMenu(self):
71 menu = wx.Menu()
72 item = menu.Append(-1, "Recent Searches")
73 item.Enable(False)
74 for txt in [ "You can maintain",
75 "a list of old",
76 "search strings here",
77 "and bind EVT_MENU to",
78 "catch their selections" ]:
79 menu.Append(-1, txt)
80 return menu
81
82
83#----------------------------------------------------------------------
84
85def runTest(frame, nb, log):
86 win = TestPanel(nb, log)
87 return win
88
89#----------------------------------------------------------------------
90
91
92
93overview = """<html><body>
94<h2><center>wx.SearchCtrl</center></h2>
95
96</body></html>
97"""
98
99
100
101if __name__ == '__main__':
102 import sys,os
103 import run
104 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
105