]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/wxFindReplaceDialog.py
wxPython Merge #2 of 2.4 branch --> HEAD (branch tag: wxPy_2_4_merge_2)
[wxWidgets.git] / wxPython / demo / wxFindReplaceDialog.py
... / ...
CommitLineData
1
2from wxPython.wx import *
3
4#---------------------------------------------------------------------------
5
6class TestPanel(wxPanel):
7 def __init__(self, parent, log):
8 wxPanel.__init__(self, parent, -1)
9 self.log = log
10
11 b = wxButton(self, -1, "Show Find Dialog", (25, 50))
12 EVT_BUTTON(self, b.GetId(), self.OnShowFind)
13
14 b = wxButton(self, -1, "Show Find && Replace Dialog", (25, 90))
15 EVT_BUTTON(self, b.GetId(), self.OnShowFindReplace)
16
17 EVT_COMMAND_FIND(self, -1, self.OnFind)
18 EVT_COMMAND_FIND_NEXT(self, -1, self.OnFind)
19 EVT_COMMAND_FIND_REPLACE(self, -1, self.OnFind)
20 EVT_COMMAND_FIND_REPLACE_ALL(self, -1, self.OnFind)
21 EVT_COMMAND_FIND_CLOSE(self, -1, self.OnFindClose)
22
23
24 def OnShowFind(self, evt):
25 data = wxFindReplaceData()
26 dlg = wxFindReplaceDialog(self, data, "Find")
27 dlg.data = data # save a reference to it...
28 dlg.Show(True)
29
30
31 def OnShowFindReplace(self, evt):
32 data = wxFindReplaceData()
33 dlg = wxFindReplaceDialog(self, data, "Find & Replace", wxFR_REPLACEDIALOG)
34 dlg.data = data # save a reference to it...
35 dlg.Show(True)
36
37
38 def OnFind(self, evt):
39 map = {
40 wxEVT_COMMAND_FIND : "FIND",
41 wxEVT_COMMAND_FIND_NEXT : "FIND_NEXT",
42 wxEVT_COMMAND_FIND_REPLACE : "REPLACE",
43 wxEVT_COMMAND_FIND_REPLACE_ALL : "REPLACE_ALL",
44 }
45 et = evt.GetEventType()
46
47 try:
48 evtType = map[et]
49 except KeyError:
50 evtType = "**Unknown Event Type**"
51
52 if et == wxEVT_COMMAND_FIND_REPLACE or et == wxEVT_COMMAND_FIND_REPLACE_ALL:
53 replaceTxt = "Replace text: " + evt.GetReplaceString()
54 else:
55 replaceTxt = ""
56
57 self.log.write("%s -- Find text: %s %s Flags: %d \n" %
58 (evtType, evt.GetFindString(), replaceTxt, evt.GetFlags()))
59
60
61 def OnFindClose(self, evt):
62 self.log.write("wxFindReplaceDialog closing...\n")
63 evt.GetDialog().Destroy()
64
65#---------------------------------------------------------------------------
66
67def runTest(frame, nb, log):
68 win = TestPanel(nb, log)
69 return win
70
71#---------------------------------------------------------------------------
72
73
74
75
76overview = """\
77A generic find and replace dialog.
78"""
79
80
81
82
83if __name__ == '__main__':
84 import sys,os
85 import run
86 run.main(['', os.path.basename(sys.argv[0])])
87