[pygtk] Find string within TextBuffer
Lupine
thelupine.mailinglists at gmail.com
Fri Mar 13 19:52:44 WST 2009
Hello all,
I've read over:
http://www.pygtk.org/pygtk2tutorial/sec-TextBuffers.html
http://www.pygtk.org/pygtk2tutorial/sec-TextIters.html
...but I'm not finding what I'm looking for, which is probably really
simple for someone out there. If you can point me to another tutorial
were this is covered, or example code..either would be much appreciated.
I have a simple Python/PyGTK/Glade application, which has a gtk.TextView
that contains some text from the gtk.TextBuffer. Upon the click of the
"find" button, how can I scroll through each line of the buffer looking
for the entered string. This is what I got so far:
def on_find_dialog_ok_button_clicked(self, action):
"""This will highlight each found entry"""
findentry = self.widgets.get_widget('find_entry').get_text()
txtbuffer = self.widgets.get_widget('pref_hosts_txtview').get_buffer()
startiter = txtbuffer.get_start_iter()
enditer = txtbuffer.get_end_iter()
bufferlines = txtbuffer.get_text(startiter, enditer)
for bufferline in bufferlines:
print "looking at " + bufferline
if (re.search(findentry, bufferline)):
print "found entry: " + bufferline
print "all done looking"
The result, is that it is printing each character (one char at a time)
on each separate line, which explains why my search is failing. So what
is the proper way to look through each line for str?
Thanks,
-Lup
More information about the pygtk
mailing list