On Wed, 9 May 2001 [EMAIL PROTECTED] wrote:
>
> 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?
The buffer is empty. It always contains at least one '\n' (if there are
no lines in the buffer, where do you put the insertion point?)
> Second, how can I get back the text (or at least the range(s) of
> text positions) associated with the tag "bold"?
I am not sure about this one. Try asking Havoc ([EMAIL PROTECTED]).
> 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.
These questions are probably better asked of Havoc. If what you want is
possible, then he would know how. If it isn't possible, he would be the
one who could write the patch for GTK+ to make it possible :)
James.
--
Email: [EMAIL PROTECTED]
WWW: http://www.daa.com.au/~james/
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk