[pygtk] Re: Font setting as user inputs text in TextView/TextBuffer?

skip at pobox.com skip at pobox.com
Tue Mar 21 05:04:13 WST 2006


Responding to my own post (bad form, I know)...

Indeed, it seems that connecting to the TextBuffer's changed signal is the
correct way to set the text attributes for new insertions.  That seems like
it could get pretty inefficient if the buffer's contents get large.  My code
looks like this:

    def __init__(self, ...):
        ...
        buf.connect("changed", self.tweak_attributes)

    def tweak_attributes(self, buf):
        tt = buf.get_tag_table()
        if tt.lookup("monospace") is None:
            buf.create_tag("monospace", font="courier")
        start, end = buf.get_bounds()
        buf.apply_tag_by_name("monospace", start, end)

Is there a more efficient way to do this than applying the tag to the entire
buffer for every character change?  I'm a little paranoid about this because
in my experience the TextView/TextBuffer combination tends to bog down with
even moderate amounts of text.  When using it as the target of a logging
handler I trim the early lines if its contents grow to more than 500 lines
because of performance problems.  Maybe it's a scrolling thing, but still...

Thx,

Skip


More information about the pygtk mailing list