Thread
:
gtk widget: pixbuf / imagesurface are driving me nuts...
View Single Post
trlopes1974
2011-02-11 , 10:11
Posts: 87 | Thanked: 46 times | Joined on Nov 2010 @ lisbon, portugal
#
1
Hi
I'm going crazy with this.
I'm trying to load an image that I get from mawf dbus when music changes (album art)
This image comes in JPEG.
When I try to draw this picture on a cairo surface in the widget, ir simple draws nothing.
I've tryed everything I found.
look:
self.images = { 'fmtx0':cairo.ImageSurface.create_from_png(imagepa th + "radio_disabled.png"),
'audio0':cairo.ImageSurface.create_from_png(imagep ath + "audio.png"),
'audio1':cairo.ImageSurface.create_from_png(imagep ath + "audio_down.png"),
'next0':cairo.ImageSurface.create_from_png(imagepa th + "next.png"),
'next1':cairo.ImageSurface.create_from_png(imagepa th + "next_down.png"),
'prev0':cairo.ImageSurface.create_from_png(imagepa th + "prev.png"),
'prev1':cairo.ImageSurface.create_from_png(imagepa th + "prev_down.png"),
'play0':cairo.ImageSurface.create_from_png(imagepa th + "play.png"),
'play1':cairo.ImageSurface.create_from_png(imagepa th + "play_down.png"),
'stop0':cairo.ImageSurface.create_from_png(imagepa th + "stop.png"),
'stop1':cairo.ImageSurface.create_from_png(imagepa th + "stop_down.png")}
def drawaudio(self, imgpos):
print "DEBUG: drawing audio " + imgpos #(imgpos will be empty if the default icon is to be drawn)
cr_e = self.e_mpstatus.window.cairo_create()
cr_e.set_source_rgba(0.0, 0.0, 0.0, 0.5) # If you, like I do, have transparency in your buttons,
cr_e.set_operator(cairo.OPERATOR_SOURCE) # you need to paint the background first.
cr_e.paint()
cr_e.set_operator(cairo.OPERATOR_OVER)
if (imgpos==''):
print "DEBUG: default audio"
cr_e.set_source_surface(self.images['audio' + '0'], 0, 0) # THIS WORKS OK
cr_e.paint()
else:
print "DEBUG: specific audio album art" #THIS IS DRIVING ME NUTS/CRAZY/ZOMBIE...
#pixbuf = gtk.gdk.pixbuf_new_from_file(imgpos)
#print "FILEINFO:" + gtk.gdk.pixbuf_get_file_info(imgpos)
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(imgpos,64,64)
x = 64
y = 64
#pixbuf = pixbuf.scale_simple(64,64,gtk.gdk.INTERP_BILINEAR)
pixbuf.save("/tmp/audio0.png", 'png', options=None)
print "saved file to /tmp/audio0.png"
#self.e_mpstatus.set_from_file("/tmp/audio0.png")
#''' create a new cairo surface to place the imag
#surface = cr_e
#''' create a context to the new surface '''
#ct = cairo.Context(cr_e)
#''' create a GDK formatted Cairo context to the new Cairo native context '''
#cr_e = gtk.gdk.CairoContext(ct)
#''' draw from the pixbuf to the new surface '''
#cr_e.set_source_pixbuf(pixbuf,0,0)
#pixbuf = gtk.gdk.pixbuf_new_from_file(imagepath + "audio0.png")
#cr_e.set_source_pixbuf(pixbuf,0,0) # here's where the magic is done
cr_e.set_source_surface(cairo.ImageSurface.create_ from_png("/tmp/audio0.png), 0, 0) # here's where the magic is done
cr_e.paint()
print "file loaded" # IT SHOWS NOTHING!!! GRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
CAN SOMEONE HELP ME????
Quote & Reply
|
trlopes1974
View Public Profile
Send a private message to trlopes1974
Find all posts by trlopes1974