[pygtk] TextView: keyword highlighting

Nolwenn Le Meur nlemeur at irisa.fr
Tue May 12 17:29:33 WST 2009


Hi,

I am a newbie  and I need some help with TextView.

I would like to be able to dynamically (on insert) highlight or change 
the color of words in a TextView when those belong to a keyword list I 
have.

I have found some functions on the Internet (like the one below) but 
can't seem to make them work :(

       def highlightText(self, gtk.TextBuffer, searchStr):
           buffer.create_tag("red_foreground", foreground="red")
           start, end = buffer.get_bounds()
           finished = False
                     while finished == False:
               res = start.forward_search(searchStr, 
gtk.TEXT_SEARCH_TEXT_ONLY)
               if not res:
                   finished = True
               else:
                   matchStart, matchEnd = res
                   buffer.apply_tag_by_name("red_foreground", 
matchStart,  matchEnd)
                   start = matchEnd

Any help is appreciated
Thanks

-- 
Nolwenn



More information about the pygtk mailing list