tags:

views:

204

answers:

1

Hi to all. I have a gtk.Textview and i want to make text find and selecting this text in this textview. I have this code but, it's not true.

search_str =  self.text_to_find.get_text()
start_iter =  textbuffer.get_start_iter() 
match_start = textbuffer.get_start_iter() 
match_end =   textbuffer.get_end_iter() 
found =       start_iter.forward_search(search_str,0, None) 
if found: 
   textbuffer.select_range(match_start,match_end)

If text found, then selecting all text in textview, but i need selecting of only found text.

Thank you.

+1  A: 

start_iter.forward_search returns a tuple of the start and end matches so your found variable has both match_start and match_end in it

this should make it work:

search_str =  self.text_to_find.get_text()
start_iter =  textbuffer.get_start_iter()
# don't need these lines anymore
#match_start = textbuffer.get_start_iter() 
#match_end =   textbuffer.get_end_iter() 
found =       start_iter.forward_search(search_str,0, None) 
if found:
   match_start,match_end = found #add this line to get match_start and match_end
   textbuffer.select_range(match_start,match_end)
John
Thank you for reply, you realy helped me!
shk