]>
Commit | Line | Data |
---|---|---|
3f7f284d RD |
1 | |
2 | import wx | |
3 | ||
4 | #---------------------------------------------------------------------- | |
5 | ||
6 | class 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) | |
3c69a2ec RD |
44 | self.Bind(wx.EVT_TEXT_ENTER, self.OnDoSearch, self.search) |
45 | ##self.Bind(wx.EVT_TEXT, self.OnDoSearch, self.search) | |
46 | ||
3f7f284d RD |
47 | |
48 | def OnToggleSearchButton(self, evt): | |
0a95d336 | 49 | self.search.ShowSearchButton( evt.GetInt() ) |
3f7f284d RD |
50 | |
51 | def OnToggleCancelButton(self, evt): | |
0a95d336 | 52 | self.search.ShowCancelButton( evt.GetInt() ) |
3f7f284d RD |
53 | |
54 | def OnToggleSearchMenu(self, evt): | |
55 | if evt.GetInt(): | |
56 | self.search.SetMenu( self.MakeMenu() ) | |
57 | else: | |
58 | self.search.SetMenu(None) | |
59 | ||
60 | ||
61 | def OnSearch(self, evt): | |
62 | self.log.write("OnSearch") | |
63 | ||
64 | def OnCancel(self, evt): | |
65 | self.log.write("OnCancel") | |
66 | ||
67 | def OnDoSearch(self, evt): | |
68 | self.log.write("OnDoSearch: " + self.search.GetValue()) | |
69 | ||
70 | ||
71 | def MakeMenu(self): | |
72 | menu = wx.Menu() | |
73 | item = menu.Append(-1, "Recent Searches") | |
74 | item.Enable(False) | |
75 | for txt in [ "You can maintain", | |
76 | "a list of old", | |
77 | "search strings here", | |
78 | "and bind EVT_MENU to", | |
79 | "catch their selections" ]: | |
80 | menu.Append(-1, txt) | |
81 | return menu | |
82 | ||
83 | ||
84 | #---------------------------------------------------------------------- | |
85 | ||
86 | def runTest(frame, nb, log): | |
87 | win = TestPanel(nb, log) | |
88 | return win | |
89 | ||
90 | #---------------------------------------------------------------------- | |
91 | ||
92 | ||
93 | ||
94 | overview = """<html><body> | |
95 | <h2><center>wx.SearchCtrl</center></h2> | |
96 | ||
97 | </body></html> | |
98 | """ | |
99 | ||
100 | ||
101 | ||
102 | if __name__ == '__main__': | |
103 | import sys,os | |
104 | import run | |
105 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) | |
106 |