1 # 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
5 # 11/28/2003 - Jeff Grimmett (grimmtooth@softhome.net)
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.
14 #---------------------------------------------------------------------------
16 class TestPanel(wx
.Panel
):
17 def __init__(self
, parent
, log
):
18 wx
.Panel
.__init
__(self
, parent
, -1)
21 self
.fbtn
= wx
.Button(self
, -1, "Show Find Dialog", (25, 50))
22 self
.Bind(wx
.EVT_BUTTON
, self
.OnShowFind
, self
.fbtn
)
24 self
.frbtn
= wx
.Button(self
, -1, "Show Find && Replace Dialog", (25, 90))
25 self
.Bind(wx
.EVT_BUTTON
, self
.OnShowFindReplace
, self
.frbtn
)
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
)
33 def EnableButtons(self
):
37 def DisableButtons(self
):
41 def OnShowFind(self
, evt
):
43 data
= wx
.FindReplaceData()
44 dlg
= wx
.FindReplaceDialog(self
, data
, "Find")
45 dlg
.data
= data
# save a reference to it...
49 def OnShowFindReplace(self
, evt
):
51 data
= wx
.FindReplaceData()
52 dlg
= wx
.FindReplaceDialog(self
, data
, "Find & Replace", wx
.FR_REPLACEDIALOG
)
53 dlg
.data
= data
# save a reference to it...
57 def OnFind(self
, evt
):
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",
65 et
= evt
.GetEventType()
70 evtType
= "**Unknown Event Type**"
72 #>> Todo: the GetReplaceString() method is broken. Has to be
74 if et
== wx
.EVT_COMMAND_FIND_REPLACE
or et
== wx
.EVT_COMMAND_FIND_REPLACE_ALL
:
75 replaceTxt
= "Replace text: %s" % evt
.GetReplaceString()
79 self
.log
.write("%s -- Find text: %s Replace text: %s Flags: %d \n" %
80 (evtType
, evt
.GetFindString(), replaceTxt
, evt
.GetFlags()))
83 def OnFindClose(self
, evt
):
84 self
.log
.write("FindReplaceDialog closing...\n")
85 evt
.GetDialog().Destroy()
89 #---------------------------------------------------------------------------
91 def runTest(frame
, nb
, log
):
92 win
= TestPanel(nb
, log
)
95 #---------------------------------------------------------------------------
101 FindReplaceDialog is a standard modeless dialog which is used to allow the user
102 to search for some text (and possibly replace it with something else). The actual
103 searching is supposed to be done in the owner window which is the parent of this
104 dialog. 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
106 dialog in a modal way; <b>it is always, by design and implementation, modeless</b>.
108 FileReplaceDialog requires the use of <b>FindReplaceData</b>. This holds the
109 data for the dialog. It is used to initialize the dialog with the default values
110 and will keep the last values from the dialog when it is closed. It is also
111 updated each time a FindDialogEvent is generated so instead of using the
112 FindDialogEvent methods you can also directly query this object. <b>Care must be
113 taken not to use this object after the dialog is destroyed.</b> The data within
114 will be invalid after the parent dialog is destroyed.
120 if __name__
== '__main__':
123 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])