2003-12-08 20:23:28 -05:00
|
|
|
# 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.
|
2005-04-19 18:39:43 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
import wx
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2001-10-12 19:26:38 -04:00
|
|
|
def __init__(self, parent, log):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2001-10-12 19:26:38 -04:00
|
|
|
self.log = log
|
|
|
|
|
2005-03-28 15:08:38 -05:00
|
|
|
self.fbtn = wx.Button(self, -1, "Show Find Dialog", (25, 50))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnShowFind, self.fbtn)
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2005-03-28 15:08:38 -05:00
|
|
|
self.frbtn = wx.Button(self, -1, "Show Find && Replace Dialog", (25, 90))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnShowFindReplace, self.frbtn)
|
2001-10-12 19:26:38 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
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)
|
2001-10-12 19:26:38 -04:00
|
|
|
|
2005-03-28 15:08:38 -05:00
|
|
|
def EnableButtons(self):
|
|
|
|
self.fbtn.Enable()
|
|
|
|
self.frbtn.Enable()
|
|
|
|
|
|
|
|
def DisableButtons(self):
|
|
|
|
self.fbtn.Disable()
|
|
|
|
self.frbtn.Disable()
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
def OnShowFind(self, evt):
|
2005-03-28 15:08:38 -05:00
|
|
|
self.DisableButtons()
|
2003-12-08 20:23:28 -05:00
|
|
|
data = wx.FindReplaceData()
|
|
|
|
dlg = wx.FindReplaceDialog(self, data, "Find")
|
2001-10-12 19:26:38 -04:00
|
|
|
dlg.data = data # save a reference to it...
|
2003-03-25 01:35:27 -05:00
|
|
|
dlg.Show(True)
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
def OnShowFindReplace(self, evt):
|
2005-03-28 15:08:38 -05:00
|
|
|
self.DisableButtons()
|
2003-12-08 20:23:28 -05:00
|
|
|
data = wx.FindReplaceData()
|
|
|
|
dlg = wx.FindReplaceDialog(self, data, "Find & Replace", wx.FR_REPLACEDIALOG)
|
2001-10-12 19:26:38 -04:00
|
|
|
dlg.data = data # save a reference to it...
|
2003-03-25 01:35:27 -05:00
|
|
|
dlg.Show(True)
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
def OnFind(self, evt):
|
|
|
|
map = {
|
2003-12-08 20:23:28 -05:00
|
|
|
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",
|
2001-10-12 19:26:38 -04:00
|
|
|
}
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2001-10-12 19:26:38 -04:00
|
|
|
et = evt.GetEventType()
|
2003-12-08 20:23:28 -05:00
|
|
|
|
|
|
|
if et in map:
|
2001-10-12 19:26:38 -04:00
|
|
|
evtType = map[et]
|
2003-12-08 20:23:28 -05:00
|
|
|
else:
|
2001-10-12 19:26:38 -04:00
|
|
|
evtType = "**Unknown Event Type**"
|
|
|
|
|
2005-04-19 18:39:43 -04:00
|
|
|
if et in [wx.wxEVT_COMMAND_FIND_REPLACE, wx.wxEVT_COMMAND_FIND_REPLACE_ALL]:
|
2003-12-08 20:23:28 -05:00
|
|
|
replaceTxt = "Replace text: %s" % evt.GetReplaceString()
|
2001-10-12 19:26:38 -04:00
|
|
|
else:
|
|
|
|
replaceTxt = ""
|
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
self.log.write("%s -- Find text: %s Replace text: %s Flags: %d \n" %
|
2001-10-12 19:26:38 -04:00
|
|
|
(evtType, evt.GetFindString(), replaceTxt, evt.GetFlags()))
|
|
|
|
|
|
|
|
|
|
|
|
def OnFindClose(self, evt):
|
2003-12-08 20:23:28 -05:00
|
|
|
self.log.write("FindReplaceDialog closing...\n")
|
2001-10-12 19:26:38 -04:00
|
|
|
evt.GetDialog().Destroy()
|
2005-03-28 15:08:38 -05:00
|
|
|
self.EnableButtons()
|
|
|
|
|
2001-10-12 19:26:38 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
2003-12-08 20:23:28 -05:00
|
|
|
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
|
|
|
|
<u>must have a parent window</u>. Also note that there is no way to use this
|
|
|
|
dialog in a modal way; <b>it is always, by design and implementation, modeless</b>.
|
|
|
|
|
|
|
|
FileReplaceDialog requires the use of <b>FindReplaceData</b>. 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. <b>Care must be
|
|
|
|
taken not to use this object after the dialog is destroyed.</b> The data within
|
|
|
|
will be invalid after the parent dialog is destroyed.
|
2001-10-12 19:26:38 -04:00
|
|
|
"""
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-07-02 19:13:10 -04:00
|
|
|
|