[pygtk] Re: Font setting as user inputs text in
TextView/TextBuffer?
Tony Nelson
tonynelson at georgeanelson.com
Tue Mar 21 06:48:52 WST 2006
At 3:04 PM -0600 3/20/06, skip at pobox.com wrote:
>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...
I do something much stupider: I call TextView.modify_font(). I do fiddle
around with styles for some other things, but this seems to work for
setting one font for the whole widget.
____________________________________________________________________
TonyN.:' <mailto:tonynelson at georgeanelson.com>
' <http://www.georgeanelson.com/>
More information about the pygtk
mailing list