passagesearchframe.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import wx
  2. from searchpanels import FindPanel, ReplacePanel
  3. class PassageSearchFrame(wx.Frame):
  4. """
  5. This allows a user to do search and replaces on a PassageFrame.
  6. By default, this shows the Find tab initially, but this can be
  7. set via the constructor.
  8. """
  9. def __init__(self, parent, passageFrame, app, initialState = 0):
  10. self.passageFrame = passageFrame
  11. self.app = app
  12. wx.Frame.__init__(self, parent, title = 'Find/Replace In Passage')
  13. panel = wx.Panel(self)
  14. panelSizer = wx.BoxSizer(wx.VERTICAL)
  15. panel.SetSizer(panelSizer)
  16. self.notebook = wx.Notebook(panel)
  17. self.findPanel = FindPanel(self.notebook, onFind = self.passageFrame.findRegexp, \
  18. onClose = self.Close)
  19. self.replacePanel = ReplacePanel(self.notebook, onFind = self.passageFrame.findRegexp, \
  20. onReplace = self.passageFrame.replaceOneRegexp, \
  21. onReplaceAll = self.passageFrame.replaceAllRegexps, \
  22. onClose = self.Close)
  23. self.notebook.AddPage(self.findPanel, 'Find')
  24. self.notebook.AddPage(self.replacePanel, 'Replace')
  25. self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onChangeTab)
  26. self.notebook.ChangeSelection(initialState)
  27. if initialState == PassageSearchFrame.FIND_TAB:
  28. self.findPanel.focus()
  29. else:
  30. self.replacePanel.focus()
  31. panelSizer.Add(self.notebook, 1, wx.EXPAND)
  32. panelSizer.Fit(self)
  33. self.SetIcon(self.app.icon)
  34. self.Show()
  35. def onChangeTab(self, event):
  36. if event.GetSelection() == PassageSearchFrame.FIND_TAB:
  37. self.findPanel.focus()
  38. else:
  39. self.replacePanel.focus()
  40. # for some reason, we have to manually propagate the event from here
  41. event.Skip(True)
  42. FIND_TAB = 0
  43. REPLACE_TAB = 1