AlbumArt widget is now an event box
This allows me to catch a button-press-event and show a file chooser to select an image as the new album art for the currently playing song.
This commit is contained in:
parent
6e429d1fd2
commit
3ce9240655
|
@ -3,9 +3,10 @@ import libsaria
|
|||
import gtk
|
||||
gdk = gtk.gdk
|
||||
|
||||
sources = libsaria.sources
|
||||
from libsaria import threads
|
||||
|
||||
lock = threads.get_mutex("album_art")
|
||||
lock = threads.get_mutex("album_art")
|
||||
|
||||
class Image(gtk.Image):
|
||||
def __init__(self):
|
||||
|
@ -32,7 +33,8 @@ class Image(gtk.Image):
|
|||
self.set_from_pixbuf(buf)
|
||||
return True
|
||||
|
||||
class AlbumArt(Image):
|
||||
|
||||
class AlbumArtImage(Image):
|
||||
def __init__(self):
|
||||
Image.__init__(self)
|
||||
self.hide()
|
||||
|
@ -40,12 +42,16 @@ class AlbumArt(Image):
|
|||
self.set("images/ocarina.png")
|
||||
self.set_has_tooltip(True)
|
||||
self.connect("query-tooltip", self.tooltip)
|
||||
self.connect("button-press-event", self.clicked)
|
||||
libsaria.event.invite("PRELOAD", self.preload)
|
||||
libsaria.event.invite("POSTGETART", self.set)
|
||||
|
||||
def preload(self, *args):
|
||||
self.file = "images/ocarina.png"
|
||||
|
||||
def clicked(self, widget, event):
|
||||
print widget, event
|
||||
|
||||
def tooltip(self, image, x, y, keyboard, tip):
|
||||
image = gtk.Image()
|
||||
image.set_from_file(self.file)
|
||||
|
@ -53,17 +59,48 @@ class AlbumArt(Image):
|
|||
return True
|
||||
|
||||
def set(self, file=None):
|
||||
gdk.threads_enter()
|
||||
#print "attempting to enter"
|
||||
#gdk.threads_enter()
|
||||
#print "entered"
|
||||
for i in xrange(2):
|
||||
self.file = file
|
||||
self.set_from_file(self.file)
|
||||
if self.set_height(64) == True:
|
||||
break
|
||||
try:
|
||||
self.set_from_file(self.file)
|
||||
if self.set_height(64) == True:
|
||||
break
|
||||
except:
|
||||
pass
|
||||
file = "images/ocarina.png"
|
||||
gdk.threads_leave()
|
||||
#print "threads leaving"
|
||||
#gdk.threads_leave()
|
||||
|
||||
def set_height(self, new_h):
|
||||
size = self.size_request()
|
||||
if size[1] == new_h:
|
||||
return
|
||||
return Image.set_height(self, new_h)
|
||||
|
||||
|
||||
class AlbumArt(gtk.EventBox):
|
||||
def __init__(self):
|
||||
gtk.EventBox.__init__(self)
|
||||
self.image = AlbumArtImage()
|
||||
self.add(self.image)
|
||||
self.connect("button-press-event", self.clicked)
|
||||
self.show()
|
||||
|
||||
def clicked(self, widget, event):
|
||||
if event.button != 1:
|
||||
return
|
||||
if sources.cur_lib_id == -1:
|
||||
return
|
||||
from ocarina import fsselect
|
||||
path = fsselect.file("Select an image")
|
||||
print "Selected file: %s" % path
|
||||
try:
|
||||
#self.image.set(path)
|
||||
sources.library.set_attr(sources.cur_lib_id, "art", path)
|
||||
except Exception, e:
|
||||
print e
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue