[pygtk] Embedding images into TextBuffer.

Mikhail Sobolev mss at mawhrin.net
Tue Jul 27 02:37:04 WST 2004


Hi

I'd like to embed images into my TextBuffer, and then center them.

The code snippet at the moment is:

    tv = gtk.TextView ()
    buf = tv.get_buffer ()

    buf.create_tag ('center-image', justification = gtk.JUSTIFY_CENTER)

    ...

    pixbuf = gtk.gdk.pixbuf_new_from_file ('path/to/image.png')

    ...

    # putting the image at the end.
    sob, eob = buf.get_bounds ()

    mark = buf.create_mark (None, eob)

    buf.insert_pixbuf (eob, pixbuf)

    buf.apply_style_by_name ('center-image', buf.get_iter_from_mark (mark), buf.getbounds ()[1])

    ...

It maybe a bit awkward, while I think I understand every step :)
However, the resulting image does not get centered.

Is something missing from the code which actually does the right thing?

(FWIW, gtk is of version 2.4.3, pygtk is of version 2.2.0)

Regards

--
Misha
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20040726/7f6fdd54/attachment.bin


More information about the pygtk mailing list