Hi Robin,
This is the code in the OnFindNex method i'm using..
I'm using the unicode wxPython version,
BTW, The problem is that everytime i call the FinText STC method for searching text "top direction" it crashes it there are no
results
# -------------------------------------------
# FIND next
# VERIFY!
# -------------------------------------------
def OnFindNext(self, event=None, s_from=-1):
print "OnFindNext"
if event.__class__ == WindowsFinder.Finder:
win = event
else:
win = event.GetEventObject().GetParent()
doc = self.GetTextCtrl()
if not doc:
wxBell()
return
doc.selectionChanged = 0
if win.combo.GetValue() == '':
return
query = win.combo.GetValue()
if win.document.GetValue() == 0:
minPos = doc.GetSelection()[0]
maxPos = doc.GetSelection()[1]
if win.direction1.GetValue() == 1:
minPos = doc.GetSelection()[1]
maxPos = doc.GetSelection()[0]
else:
minPos = doc.GetSelection()[0]
maxPos = doc.GetLength()
if minPos == doc.GetLength():
minPos = 0
if s_from != -1:
minPos = s_from
if win.direction1.GetValue() == 1:
minPos = doc.GetSelection()[0] - 1
maxPos = 0
if s_from != -1:
minPos = doc.GetLength()
maxPos = 0
options = '0'
# ------------------------
# checking FIND options...
# ------------------------
if win.whole_word.GetValue() == 1:
options = 'wxSTC_FIND_WHOLEWORD'
if win.reg.GetValue() == 1:
options = 'wxSTC_FIND_REGEXP'
if win.case.GetValue() == 1:
options = '%s | wxSTC_FIND_MATCHCASE' % options
# ------------------------
# MARK ALL
# ------------------------
if win.all.GetId() == event.GetId():
minPos = 0
maxPos = doc.GetLength()
while 1:
result = doc.FindText(minPos, maxPos, query, eval(options))
if result == -1:
break
return -1
doc.SetSelection(result,result)
line = doc.GetCurrentLine()
doc.MarkerAdd(line, 0)
minPos = result + len(query)
doc.EnsureVisible(line)
wxCallAfter(doc.SetSelection, result, result + len(query))
return 0
# ------------------------
# NEW SEARCH
# ------------------------
#if win.doNewSearch == 1 or query != win.lastSearched or doc.selectionChanged == 1:
if win.doNewSearch == 1:
print "NEW", minPos, maxPos,options
result = doc.FindText(minPos, maxPos, query, eval(options))
win.doNewSearch = 0
else:
# --------------------
# NEXT SEARCH
# --------------------
minPos = doc.GetSelection()[1]
maxPos = doc.GetLength()
if win.direction1.GetValue() == 1:
#minPos = doc.GetSelection()[0] - 1
minPos = doc.GetSelectionStart() - 1
maxPos = 0
#minPos = 0
#maxPos = doc.GetSelection()[0] - 1
print "->NEXT...",minPos, maxPos
result = doc.FindText(minPos, maxPos, query, eval(options))
if query not in self.searchedWords:
self.searchedWords.insert(0, query)
# returned results...
if result >= 0:
doc.lastSearchedWord = query
doc.query_options = options
#doc.SetSelection(result, result + len(query))
line = doc.LineFromPosition(result)
doc.EnsureVisible(line)
wxCallAfter(doc.SetSelection, result, result + len(query))
else:
if win.doNewSearch == 0 and (minPos > 0 or minPos == -1) and win.document.GetValue() == 1:
print "search again..."
win.doNewSearch = 1
self.OnFindNext(event, 0)
return -1
else:
wxMessageDialog(self, "%s: %s" % (self.langClass.C_NO_RES, query), About.title, wxOK | wxICON_EXCLAMATION
).ShowModal()
# save settings
win.lastSearched = query