]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | import wx | |
0122b7e3 RD |
13 | |
14 | #--------------------------------------------------------------------------- | |
15 | ||
8fa876ca | 16 | class 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 | ||
8fa876ca RD |
21 | b = wx.Button(self, -1, "Show Find Dialog", (25, 50)) |
22 | self.Bind(wx.EVT_BUTTON, self.OnShowFind, b) | |
23 | ||
24 | b = wx.Button(self, -1, "Show Find && Replace Dialog", (25, 90)) | |
25 | self.Bind(wx.EVT_BUTTON, self.OnShowFindReplace, b) | |
0122b7e3 | 26 | |
0122b7e3 | 27 | |
8fa876ca RD |
28 | # jg - 11/28/03 - corrected a long standing issue here where |
29 | # EVT_COMMAND_FIND_* was being used for these event binders | |
30 | # instead of the actual event IDs shown below. As a result, | |
31 | # onFind() was never showing the appropriate type. I guess | |
32 | # nobody really paid much attention to that little | |
33 | # debugging window :-) | |
34 | # | |
35 | self.Bind(wx.EVT_FIND, self.OnFind) | |
36 | self.Bind(wx.EVT_FIND_NEXT, self.OnFind) | |
37 | self.Bind(wx.EVT_FIND_REPLACE, self.OnFind) | |
38 | self.Bind(wx.EVT_FIND_REPLACE_ALL, self.OnFind) | |
39 | self.Bind(wx.EVT_FIND_CLOSE, self.OnFindClose) | |
0122b7e3 RD |
40 | |
41 | ||
42 | def OnShowFind(self, evt): | |
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): | |
8fa876ca RD |
50 | data = wx.FindReplaceData() |
51 | dlg = wx.FindReplaceDialog(self, data, "Find & Replace", wx.FR_REPLACEDIALOG) | |
0122b7e3 | 52 | dlg.data = data # save a reference to it... |
1e4a197e | 53 | dlg.Show(True) |
0122b7e3 RD |
54 | |
55 | ||
56 | def OnFind(self, evt): | |
57 | map = { | |
8fa876ca RD |
58 | wx.wxEVT_COMMAND_FIND : "FIND", |
59 | wx.wxEVT_COMMAND_FIND_NEXT : "FIND_NEXT", | |
60 | wx.wxEVT_COMMAND_FIND_REPLACE : "REPLACE", | |
61 | wx.wxEVT_COMMAND_FIND_REPLACE_ALL : "REPLACE_ALL", | |
0122b7e3 | 62 | } |
8fa876ca | 63 | |
0122b7e3 | 64 | et = evt.GetEventType() |
8fa876ca | 65 | |
8fa876ca | 66 | if et in map: |
0122b7e3 | 67 | evtType = map[et] |
8fa876ca | 68 | else: |
0122b7e3 RD |
69 | evtType = "**Unknown Event Type**" |
70 | ||
8fa876ca RD |
71 | #>> Todo: the GetReplaceString() method is broken. Has to be |
72 | # fixed. | |
73 | if et == wx.EVT_COMMAND_FIND_REPLACE or et == wx.EVT_COMMAND_FIND_REPLACE_ALL: | |
74 | replaceTxt = "Replace text: %s" % evt.GetReplaceString() | |
0122b7e3 RD |
75 | else: |
76 | replaceTxt = "" | |
77 | ||
95bfd958 | 78 | self.log.write("%s -- Find text: %s Replace text: %s Flags: %d \n" % |
0122b7e3 RD |
79 | (evtType, evt.GetFindString(), replaceTxt, evt.GetFlags())) |
80 | ||
81 | ||
82 | def OnFindClose(self, evt): | |
8fa876ca | 83 | self.log.write("FindReplaceDialog closing...\n") |
0122b7e3 RD |
84 | evt.GetDialog().Destroy() |
85 | ||
86 | #--------------------------------------------------------------------------- | |
87 | ||
88 | def runTest(frame, nb, log): | |
89 | win = TestPanel(nb, log) | |
90 | return win | |
91 | ||
92 | #--------------------------------------------------------------------------- | |
93 | ||
94 | ||
95 | ||
96 | ||
97 | overview = """\ | |
8fa876ca RD |
98 | FindReplaceDialog is a standard modeless dialog which is used to allow the user |
99 | to search for some text (and possibly replace it with something else). The actual | |
100 | searching is supposed to be done in the owner window which is the parent of this | |
101 | dialog. Note that it means that unlike for the other standard dialogs this one | |
102 | <u>must have a parent window</u>. Also note that there is no way to use this | |
103 | dialog in a modal way; <b>it is always, by design and implementation, modeless</b>. | |
104 | ||
105 | FileReplaceDialog requires the use of <b>FindReplaceData</b>. This holds the | |
106 | data for the dialog. It is used to initialize the dialog with the default values | |
107 | and will keep the last values from the dialog when it is closed. It is also | |
108 | updated each time a FindDialogEvent is generated so instead of using the | |
109 | FindDialogEvent methods you can also directly query this object. <b>Care must be | |
110 | taken not to use this object after the dialog is destroyed.</b> The data within | |
111 | will be invalid after the parent dialog is destroyed. | |
0122b7e3 | 112 | """ |
1fded56b RD |
113 | |
114 | ||
115 | ||
116 | ||
117 | if __name__ == '__main__': | |
118 | import sys,os | |
119 | import run | |
120 | run.main(['', os.path.basename(sys.argv[0])]) | |
121 |