[pygtk] drawing and modifying svg file

François Sénéquier francois.senequier at netcourrier.com
Mon Sep 15 16:43:48 WST 2008


>> I would load and SVG file (XML file so a text file), modify it
>> (changing a color, moving a part...) by the DOM/XML interface (or
>> directly adding or replacing text) and create again an gtk.gdk.pixbuf
>> without creating another SVG file. 
>>
>> So the solution could be to load the text file, modify it and create a
>> new pixbuf from the loaded modified text (not the file)... 
>>
>> But with the gtk.gdk.pixbuf it is possible to create a pixbuf from a
>> file but it seems to be impossible to create a pixbuf from a SVG
>> string variable ?
>>
>> I don't want to create several svg files but modifying dynamically the
>> content of an unique svg file (after loaded it) and then draw it.
>>
>
>Use PixbufLoader('svg')
>
>def svg_str_to_pixbuf(txt):
>    '''Load pixbuf from a svg str.'''
>    pl = gtk.gdk.PixbufLoader('svg')
>    pl.write(txt)
>    pl.close()
>    pix = pl.get_pixbuf()
>    return pix

Hi thank you for your help...

I use your solution to create pixbuf and drawing it on a DrawingArea...
But some problem of memory occurs : the memory of pixbuf is not released... After drawing the pixbuf, the variable containing the pixbuf is not maintened in memory (local variable in a method) but the pixbuf content is not released...

I was obligated to force the gargbage collector to update the memory with the following code :

import gc

gc.collect()

Thanks








More information about the pygtk mailing list