[pygtk] saving text with layout

Thomas Mills Hinkle tmhinkle at gmail.com
Mon Oct 2 18:22:50 WST 2006

On 10/2/06, Pascal DUCHATELLE <pduchatelle at yahoo.fr> wrote:
> Hello,
> Still trying to use pango markup (and other) in a textview (at least). I
> used the pygtk demo file testext.py which is a basic text editor. There is
> a menu that allows the user to load an aexample file containing many text
> demo features (background color, greek, hebew, german, arabic characters,
> inserting image. I think I remember bold, italic, etc.)
> Anyway I save the file with the save menu option. When I loaded back the
> saved file, all the layout (I'm not sure layout is the appropriate word) =
> gone.
> Is this just for display or is there something wrong in what I'm doing ?
> How do one saves the layout (the bold, italic, and so on modifications do=
> on the text) ?

As far as I know, there is no simple way to do this. I created a special
subclass of gtk.TextBuffer in my own application to support all of this sort
of thing. I used pango.parse_markup() to get my text and attributes, and
then I had to use the attributes to set tags for my text buffer. In order to
get text back with markup, I had to keep track of my own tags and then
convert from the attributes on the tags back to pango-style markup. The
result is that with my subclass, you can call get_text() and get a marked-up
copy of the text with formatting included; similarly, you can hand
set_text() markup and it will do the right thing.

You're welcome to look at or use the code though it wasn't designed as a
library for others to use so there are a few things you'd need to muck about
with I'm sure (there are some application-specific debug calls, for


The get_text and set_text methods are what you want, I think.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20061002/b36524c6/at=

More information about the pygtk mailing list