The following little script displays a bit of text in bold:
import gtk
window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
window.set_title("title")
window.connect("destroy", gtk.mainquit)
v = gtk.GtkTextView()
window.add(v)
buf = v.get_buffer()
# some text rendered in bold
startoff = buf.get_char_count()
print startoff, "->",
istart = buf.get_iter_at_offset(startoff)
buf.insert(istart, "Spam 'n' Eggs\n")
# istart was invalidated by the buffer mod, so we must recreate it
istart = buf.get_iter_at_offset(startoff)
start = buf.create_mark("start", istart, gtk.TRUE)
endoff = buf.get_char_count()
print endoff
iend = buf.get_iter_at_offset(endoff)
end = buf.create_mark("end", iend, gtk.TRUE)
tag = buf.create_tag("bold")
tag.set_property("weight", 700)
buf.apply_tag(tag, istart, iend)
window.show_all()
gtk.mainloop()
I have two questions. First, why is buf.get_char_count() 1 when the buffer
is empty? Second, how can I get back the text (or at least the range(s) of
text positions) associated with the tag "bold"? In the example, I'm using a
tag to affect the text's display properties, but I'd like to eventually
manage insertion and deletion of buffer text using tags so that I could (for
example), mark certain text "transient" and delete it later on by tag name
without having to remember where it was originally inserted or where it
might be located in the face of other changes to the buffer's contents.
Thanks,
--
Skip Montanaro ([EMAIL PROTECTED])
(847)971-7098
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk