Reply
Thread Tools
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????
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#2
Hi trlopes1974,

I can not look at my source code at the moment, so I don't know
if it helps, but I did something similiar in my media-player-widget.

nicolai
 

The Following User Says Thank You to nicolai For This Useful Post:
Posts: 87 | Thanked: 46 times | Joined on Nov 2010 @ lisbon, portugal
#3
That's C ( i'm using python) . I tryed to understand but it seems your're not using cairo ImageSurface, you use pixbufs directly.
I'm having a real BIG headhake on this S/#(&%/%$)(&/$#)"$%""%$". ....
 
Posts: 87 | Thanked: 46 times | Joined on Nov 2010 @ lisbon, portugal
#4
by the way, the png saved form the pixbuf to /tmp/audio0.png is OK in gimp it shows-me exactly the attributes that other pngs I'm using...
.
.
.
And thanks once more nikolai
 
Reply


 
Forum Jump


All times are GMT. The time now is 20:42.