]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FindReplaceDialog.py
'[1219035] cleanup: miscellaneous' and minor source cleaning.
[wxWidgets.git] / wxPython / demo / FindReplaceDialog.py
CommitLineData
8fa876ca
RD
1# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
5# 11/28/2003 - Jeff Grimmett (grimmtooth@softhome.net)
6#
7# o Changed the event binding slightly.
edc88f7c 8
8fa876ca
RD
9
10import wx
0122b7e3
RD
11
12#---------------------------------------------------------------------------
13
8fa876ca 14class TestPanel(wx.Panel):
0122b7e3 15 def __init__(self, parent, log):
8fa876ca 16 wx.Panel.__init__(self, parent, -1)
0122b7e3
RD
17 self.log = log
18
daee9709
RD
19 self.fbtn = wx.Button(self, -1, "Show Find Dialog", (25, 50))
20 self.Bind(wx.EVT_BUTTON, self.OnShowFind, self.fbtn)
8fa876ca 21
daee9709
RD
22 self.frbtn = wx.Button(self, -1, "Show Find && Replace Dialog", (25, 90))
23 self.Bind(wx.EVT_BUTTON, self.OnShowFindReplace, self.frbtn)
0122b7e3 24
8fa876ca
RD
25 self.Bind(wx.EVT_FIND, self.OnFind)
26 self.Bind(wx.EVT_FIND_NEXT, self.OnFind)
27 self.Bind(wx.EVT_FIND_REPLACE, self.OnFind)
28 self.Bind(wx.EVT_FIND_REPLACE_ALL, self.OnFind)
29 self.Bind(wx.EVT_FIND_CLOSE, self.OnFindClose)
0122b7e3 30
daee9709
RD
31 def EnableButtons(self):
32 self.fbtn.Enable()
33 self.frbtn.Enable()
34
35 def DisableButtons(self):
36 self.fbtn.Disable()
37 self.frbtn.Disable()
0122b7e3
RD
38
39 def OnShowFind(self, evt):
daee9709 40 self.DisableButtons()
8fa876ca
RD
41 data = wx.FindReplaceData()
42 dlg = wx.FindReplaceDialog(self, data, "Find")
0122b7e3 43 dlg.data = data # save a reference to it...
1e4a197e 44 dlg.Show(True)
0122b7e3
RD
45
46
47 def OnShowFindReplace(self, evt):
daee9709 48 self.DisableButtons()
8fa876ca
RD
49 data = wx.FindReplaceData()
50 dlg = wx.FindReplaceDialog(self, data, "Find & Replace", wx.FR_REPLACEDIALOG)
0122b7e3 51 dlg.data = data # save a reference to it...
1e4a197e 52 dlg.Show(True)
0122b7e3
RD
53
54
55 def OnFind(self, evt):
56 map = {
8fa876ca
RD
57 wx.wxEVT_COMMAND_FIND : "FIND",
58 wx.wxEVT_COMMAND_FIND_NEXT : "FIND_NEXT",
59 wx.wxEVT_COMMAND_FIND_REPLACE : "REPLACE",
60 wx.wxEVT_COMMAND_FIND_REPLACE_ALL : "REPLACE_ALL",
0122b7e3 61 }
8fa876ca 62
0122b7e3 63 et = evt.GetEventType()
8fa876ca 64
8fa876ca 65 if et in map:
0122b7e3 66 evtType = map[et]
8fa876ca 67 else:
0122b7e3
RD
68 evtType = "**Unknown Event Type**"
69
edc88f7c 70 if et in [wx.wxEVT_COMMAND_FIND_REPLACE, wx.wxEVT_COMMAND_FIND_REPLACE_ALL]:
8fa876ca 71 replaceTxt = "Replace text: %s" % evt.GetReplaceString()
0122b7e3
RD
72 else:
73 replaceTxt = ""
74
95bfd958 75 self.log.write("%s -- Find text: %s Replace text: %s Flags: %d \n" %
0122b7e3
RD
76 (evtType, evt.GetFindString(), replaceTxt, evt.GetFlags()))
77
78
79 def OnFindClose(self, evt):
8fa876ca 80 self.log.write("FindReplaceDialog closing...\n")
0122b7e3 81 evt.GetDialog().Destroy()
daee9709
RD
82 self.EnableButtons()
83
0122b7e3
RD
84
85#---------------------------------------------------------------------------
86
87def runTest(frame, nb, log):
88 win = TestPanel(nb, log)
89 return win
90
91#---------------------------------------------------------------------------
92
93
94
95
96overview = """\
8fa876ca
RD
97FindReplaceDialog is a standard modeless dialog which is used to allow the user
98to search for some text (and possibly replace it with something else). The actual
99searching is supposed to be done in the owner window which is the parent of this
100dialog. Note that it means that unlike for the other standard dialogs this one
101<u>must have a parent window</u>. Also note that there is no way to use this
102dialog in a modal way; <b>it is always, by design and implementation, modeless</b>.
103
104FileReplaceDialog requires the use of <b>FindReplaceData</b>. This holds the
105data for the dialog. It is used to initialize the dialog with the default values
106and will keep the last values from the dialog when it is closed. It is also
107updated each time a FindDialogEvent is generated so instead of using the
108FindDialogEvent methods you can also directly query this object. <b>Care must be
109taken not to use this object after the dialog is destroyed.</b> The data within
110will be invalid after the parent dialog is destroyed.
0122b7e3 111"""
1fded56b
RD
112
113
114
115
116if __name__ == '__main__':
117 import sys,os
118 import run
8eca4fef 119 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 120