[wxPython] Finding a string within a textbox

I'm trying to search for a given string within a wxTextCtrl. I've tried
the following...

foundpoint = string.find(self.textbox.GetValue(),searchString,startPoint)
if foundpoint <> -1:
                     self.textbox.SetInsertionPoint(foundpoint)

This works as long as there are no newlines within
self.textbox.GetValue(). If there are, then the insertion point is off by
a few locations.

Suggestions?

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Keith Douglas writes:

I'm trying to search for a given string within a wxTextCtrl. I've tried
the following...

foundpoint = string.find(self.textbox.GetValue(),searchString,startPoint)
if foundpoint <> -1:
                     self.textbox.SetInsertionPoint(foundpoint)

This works as long as there are no newlines within
self.textbox.GetValue(). If there are, then the insertion point is off by
a few locations.

[gazes deeply into his crystal ball]
[looks up and says...]

You are running Windows?

The string returned from the wxTextCtrl has "\r\n" where there are newlines
in the widget, yes?

It behaves as you'd expect, under wxGTK+... (newlines are "\n").

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

>
> This works as long as there are no newlines within
> self.textbox.GetValue(). If there are, then the insertion point is off

by

> a few locations.

[gazes deeply into his crystal ball]
[looks up and says...]

You are running Windows?

The string returned from the wxTextCtrl has "\r\n" where there are

newlines

in the widget, yes?

It behaves as you'd expect, under wxGTK+... (newlines are "\n").

I think GetValue returns the string with only "\n" on either platform,
however the win32 control uses "\r\n" internally, so this may be where the
discrepancy lies. IOW, SetInsertionPoint is counting positions on lines
with "\r\n" at the end but you are only searching a string with "\n" at the
end of lines.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users