1

I'm presently playing with gtk.pixbuf in python. In the API, the subpixbuf function is described as returning a pixbuf that shares data with the original pixbuf :

The subpixbuf() method creates a new gtk.gdk.Pixbuf that represents a sub-region of the pixbuf. The new pixbuf shares its pixels with the original pixbuf, so writing to one affects both.

But...

when I'm trying to divide a pixbuf in a list of subpixbuf and assign a value to each item, the original pixbuf stays the same.

animation.subpixbuf=[]
animation.pixbuf.fill(self.LIGHT_SQ_COLOR)
for i in range(64) :
   animation.subpixbuf += [animation.pixbuf.subpixbuf((7-i%8)*self.sq_width (i/8)*self.sq_width,w,w)]
   animation.subpixbuf[i]=self.squares[63-i]

Any ideas on how to compose a pixbuf from a bunch of subpixbufs ?

Thanks.

Jacques Gaudin
  • 15,779
  • 10
  • 54
  • 75

1 Answers1

1

When you do animation.subpixbuf[i]=self.squares[63-i], you're assigning subpixbuf[i] to a new Pixbuf object. You're not changing the Pixbuf previously stored in subpixbuf[i].

To do what you want to do you should take a look at the copy_area method of the Pixbuf class.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • Thanks a lot for putting me back on tracks. I can't believe I missed that one ! I was on another solution using a pixmap but yours sounds much better and straight forward. I'll definitely use it ! – Jacques Gaudin May 13 '12 at 11:43