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