[pygtk] Set markup in a TextBuffer

Thomas Mills Hinkle tmhinkle at gmail.com
Tue Nov 25 11:05:56 WST 2008


On Mon, Nov 24, 2008 at 12:27 PM, Luis Javier Peris
<javierperis at gmail.com>wrote:

> Hello everybody!
>
> I would know if there's a *simple* way having a string marked up with the
> Pango text markup language to set it in a TextBuffer, I mean the same
> purpose of *set_markup gtk.Label* method but for gtk.TextBuffer, that's:
>
> Get from a string like <b>Test</b> visualize in a textbuffer like: *Test
>
> *Thanks in advance.
>


It's not simple, but I have written a library to do this as part of my
recipe app Gourmet -- you're welcome to use it:

http://grecipe-manager.cvs.sourceforge.net/viewvc/grecipe-manager/grm/src/lib/gtk_extras/TextBufferMarkup.py?revision=1.2&view=markup

Using my library's PangoBuffer class, you can just do this...

pb = PangoBuffer()
pb.set_text('<b>Hello</b>')

As the name implies, it's designed to support any markup supported by pango
elsewhere. The library also makes it really easy to implement a basic rich
text editor to allow the user to apply these properties.

Last time this came up (
http://www.daa.com.au/pipermail/pygtk/2005-November/011314.html), Gustavo
also offered up another similar library:

http://www.gnome.org/~gjc/htmltextview.py<http://www.gnome.org/%7Egjc/htmltextview.py>

Hope this helps!

Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20081124/380e7b72/attachment.htm 


More information about the pygtk mailing list