]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/FindReplaceDialog.py
Add OS/2 to supported instances
[wxWidgets.git] / wxPython / demo / FindReplaceDialog.py
... / ...
CommitLineData
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
13
14#---------------------------------------------------------------------------
15
16class TestPanel(wx.Panel):
17 def __init__(self, parent, log):
18 wx.Panel.__init__(self, parent, -1)
19 self.log = log
20
21 self.fbtn = wx.Button(self, -1, "Show Find Dialog", (25, 50))
22 self.Bind(wx.EVT_BUTTON, self.OnShowFind, self.fbtn)
23
24 self.frbtn = wx.Button(self, -1, "Show Find && Replace Dialog", (25, 90))
25 self.Bind(wx.EVT_BUTTON, self.OnShowFindReplace, self.frbtn)
26
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)
32
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()
40
41 def OnShowFind(self, evt):
42 self.DisableButtons()
43 data = wx.FindReplaceData()
44 dlg = wx.FindReplaceDialog(self, data, "Find")
45 dlg.data = data # save a reference to it...
46 dlg.Show(True)
47
48
49 def OnShowFindReplace(self, evt):
50 self.DisableButtons()
51 data = wx.FindReplaceData()
52 dlg = wx.FindReplaceDialog(self, data, "Find & Replace", wx.FR_REPLACEDIALOG)
53 dlg.data = data # save a reference to it...
54 dlg.Show(True)
55
56
57 def OnFind(self, evt):
58 map = {
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",
63 }
64
65 et = evt.GetEventType()
66
67 if et in map:
68 evtType = map[et]
69 else:
70 evtType = "**Unknown Event Type**"
71
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()
76 else:
77 replaceTxt = ""
78
79 self.log.write("%s -- Find text: %s Replace text: %s Flags: %d \n" %
80 (evtType, evt.GetFindString(), replaceTxt, evt.GetFlags()))
81
82
83 def OnFindClose(self, evt):
84 self.log.write("FindReplaceDialog closing...\n")
85 evt.GetDialog().Destroy()
86 self.EnableButtons()
87
88
89#---------------------------------------------------------------------------
90
91def runTest(frame, nb, log):
92 win = TestPanel(nb, log)
93 return win
94
95#---------------------------------------------------------------------------
96
97
98
99
100overview = """\
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.
115"""
116
117
118
119
120if __name__ == '__main__':
121 import sys,os
122 import run
123 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
124