X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1e4a197e4c60e461b8068b0619692ea083e30b8b..61940a7061d0b5d5122b1e1e939cfa2d72596999:/wxPython/demo/wxFindReplaceDialog.py diff --git a/wxPython/demo/wxFindReplaceDialog.py b/wxPython/demo/wxFindReplaceDialog.py index c0217aedec..54cc07ee3b 100644 --- a/wxPython/demo/wxFindReplaceDialog.py +++ b/wxPython/demo/wxFindReplaceDialog.py @@ -1,56 +1,79 @@ - -from wxPython.wx import * +# 11/17/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Updated for wx namespace +# +# 11/28/2003 - Jeff Grimmett (grimmtooth@softhome.net) +# +# o Changed the event binding slightly. +# o There are issues with the GetReplaceText() method of the +# FindDialogEvent. Must be retested when this is fixed. +# + +import wx #--------------------------------------------------------------------------- -class TestPanel(wxPanel): +class TestPanel(wx.Panel): def __init__(self, parent, log): - wxPanel.__init__(self, parent, -1) + wx.Panel.__init__(self, parent, -1) self.log = log - b = wxButton(self, -1, "Show Find Dialog", (25, 50)) - EVT_BUTTON(self, b.GetId(), self.OnShowFind) + b = wx.Button(self, -1, "Show Find Dialog", (25, 50)) + self.Bind(wx.EVT_BUTTON, self.OnShowFind, b) + + b = wx.Button(self, -1, "Show Find && Replace Dialog", (25, 90)) + self.Bind(wx.EVT_BUTTON, self.OnShowFindReplace, b) - b = wxButton(self, -1, "Show Find && Replace Dialog", (25, 90)) - EVT_BUTTON(self, b.GetId(), self.OnShowFindReplace) - EVT_COMMAND_FIND(self, -1, self.OnFind) - EVT_COMMAND_FIND_NEXT(self, -1, self.OnFind) - EVT_COMMAND_FIND_REPLACE(self, -1, self.OnFind) - EVT_COMMAND_FIND_REPLACE_ALL(self, -1, self.OnFind) - EVT_COMMAND_FIND_CLOSE(self, -1, self.OnFindClose) + # jg - 11/28/03 - corrected a long standing issue here where + # EVT_COMMAND_FIND_* was being used for these event binders + # instead of the actual event IDs shown below. As a result, + # onFind() was never showing the appropriate type. I guess + # nobody really paid much attention to that little + # debugging window :-) + # + self.Bind(wx.EVT_FIND, self.OnFind) + self.Bind(wx.EVT_FIND_NEXT, self.OnFind) + self.Bind(wx.EVT_FIND_REPLACE, self.OnFind) + self.Bind(wx.EVT_FIND_REPLACE_ALL, self.OnFind) + self.Bind(wx.EVT_FIND_CLOSE, self.OnFindClose) def OnShowFind(self, evt): - data = wxFindReplaceData() - dlg = wxFindReplaceDialog(self, data, "Find") + data = wx.FindReplaceData() + dlg = wx.FindReplaceDialog(self, data, "Find") dlg.data = data # save a reference to it... dlg.Show(True) def OnShowFindReplace(self, evt): - data = wxFindReplaceData() - dlg = wxFindReplaceDialog(self, data, "Find & Replace", wxFR_REPLACEDIALOG) + data = wx.FindReplaceData() + dlg = wx.FindReplaceDialog(self, data, "Find & Replace", wx.FR_REPLACEDIALOG) dlg.data = data # save a reference to it... dlg.Show(True) def OnFind(self, evt): map = { - wxEVT_COMMAND_FIND : "FIND", - wxEVT_COMMAND_FIND_NEXT : "FIND_NEXT", - wxEVT_COMMAND_FIND_REPLACE : "REPLACE", - wxEVT_COMMAND_FIND_REPLACE_ALL : "REPLACE_ALL", + wx.wxEVT_COMMAND_FIND : "FIND", + wx.wxEVT_COMMAND_FIND_NEXT : "FIND_NEXT", + wx.wxEVT_COMMAND_FIND_REPLACE : "REPLACE", + wx.wxEVT_COMMAND_FIND_REPLACE_ALL : "REPLACE_ALL", } + et = evt.GetEventType() + + #print evt.GetReplaceString() - try: + if et in map: evtType = map[et] - except KeyError: + else: evtType = "**Unknown Event Type**" - if et == wxEVT_COMMAND_FIND_REPLACE or et == wxEVT_COMMAND_FIND_REPLACE_ALL: - replaceTxt = "Replace text: " + evt.GetReplaceString() + #>> Todo: the GetReplaceString() method is broken. Has to be + # fixed. + if et == wx.EVT_COMMAND_FIND_REPLACE or et == wx.EVT_COMMAND_FIND_REPLACE_ALL: + replaceTxt = "Replace text: %s" % evt.GetReplaceString() else: replaceTxt = "" @@ -59,7 +82,7 @@ class TestPanel(wxPanel): def OnFindClose(self, evt): - self.log.write("wxFindReplaceDialog closing...\n") + self.log.write("FindReplaceDialog closing...\n") evt.GetDialog().Destroy() #--------------------------------------------------------------------------- @@ -74,5 +97,27 @@ def runTest(frame, nb, log): overview = """\ -A generic find and replace dialog. +FindReplaceDialog is a standard modeless dialog which is used to allow the user +to search for some text (and possibly replace it with something else). The actual +searching is supposed to be done in the owner window which is the parent of this +dialog. Note that it means that unlike for the other standard dialogs this one +must have a parent window. Also note that there is no way to use this +dialog in a modal way; it is always, by design and implementation, modeless. + +FileReplaceDialog requires the use of FindReplaceData. This holds the +data for the dialog. It is used to initialize the dialog with the default values +and will keep the last values from the dialog when it is closed. It is also +updated each time a FindDialogEvent is generated so instead of using the +FindDialogEvent methods you can also directly query this object. Care must be +taken not to use this object after the dialog is destroyed. The data within +will be invalid after the parent dialog is destroyed. """ + + + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])]) +