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

skip at pobox.com skip at pobox.com
Tue Mar 21 04:07:16 WST 2006


All the examples I've come across that demonstrate how to set text
attributes on TextBuffer objects insert text non-interactively, e.g.:

    text_buffer.insert(iter, "For example, you can have ")
    text_buffer.insert_with_tags_by_name(iter, "italic", "italic")
    text_buffer.insert(iter, ", ");
    text_buffer.insert_with_tags_by_name(iter, "bold", "bold")

How do I set things up so that text typed by the user is automatically
inserted with the proper attributes?  I've tried this:

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

but text entered still appears in the default font (usually something
Helvetica-ish).  I looked through the FAQ, the PyGtk example code and the
reference docs for PyGtk and Gtk but saw nothing that suggested I should be
able to "set it and forget it".  This seems like it would be a common
scenario.  Do I have to resort to catching every changed signal and
reapplying the desired tag?

Thx,

-- 
Skip Montanaro - skip at pobox.com - http://www.mojam.com/
      "The values  to which people cling  most stubbornly  under inappropriate
      conditions are those  values that were  previously  the source  of their
      greatest triumphs over adversity." -- Jared Diamond in "Collapse"


More information about the pygtk mailing list