+
+
+ def GetLastPosition(self):
+ return self.GetLength()
+
+ def GetRange(self, start, end):
+ return self.GetTextRange(start, end)
+
+ def GetSelection(self):
+ return self.GetAnchor(), self.GetCurrentPos()
+
+ def ShowPosition(self, pos):
+ line = self.LineFromPosition(pos)
+ #self.EnsureVisible(line)
+ self.GotoLine(line)
+
+ def DoFindNext(self, findData, findDlg=None):
+ backward = not (findData.GetFlags() & wx.FR_DOWN)
+ matchcase = (findData.GetFlags() & wx.FR_MATCHCASE) != 0
+ end = self.GetLastPosition()
+ textstring = self.GetRange(0, end)
+ findstring = findData.GetFindString()
+ if not matchcase:
+ textstring = textstring.lower()
+ findstring = findstring.lower()
+ if backward:
+ start = self.GetSelection()[0]
+ loc = textstring.rfind(findstring, 0, start)
+ else:
+ start = self.GetSelection()[1]
+ loc = textstring.find(findstring, start)
+
+ # if it wasn't found then restart at begining
+ if loc == -1 and start != 0:
+ if backward:
+ start = end
+ loc = textstring.rfind(findstring, 0, start)
+ else:
+ start = 0
+ loc = textstring.find(findstring, start)
+
+ # was it still not found?
+ if loc == -1:
+ dlg = wx.MessageDialog(self, 'Unable to find the search text.',
+ 'Not found!',
+ wx.OK | wx.ICON_INFORMATION)
+ dlg.ShowModal()
+ dlg.Destroy()
+ if findDlg:
+ if loc == -1:
+ wx.CallAfter(findDlg.SetFocus)
+ return
+ else:
+ findDlg.Close()
+
+ # show and select the found text
+ self.ShowPosition(loc)
+ self.SetSelection(loc, loc + len(findstring))