Use get_attrs
This changes various parts of ocarina / libsaria to use get_attrs() instead of get_attr().
This commit is contained in:
parent
7f5d0cd458
commit
c5dccdfcdf
|
@ -19,7 +19,7 @@ import playlist
|
||||||
|
|
||||||
file_to_id = library.file_to_id
|
file_to_id = library.file_to_id
|
||||||
play_id = library.play_id
|
play_id = library.play_id
|
||||||
get_attr = library.get_attr
|
get_attrs = library.get_attrs
|
||||||
reset = library.reset
|
reset = library.reset
|
||||||
inc_score = library.inc_score
|
inc_score = library.inc_score
|
||||||
inc_count = library.inc_count
|
inc_count = library.inc_count
|
||||||
|
|
|
@ -86,17 +86,17 @@ class Playlist(collection.Collection):
|
||||||
def random(self):
|
def random(self):
|
||||||
if self.size == 0:
|
if self.size == 0:
|
||||||
return
|
return
|
||||||
getattr = libsaria.collection.get_attr
|
getattr = libsaria.collection.get_attrs
|
||||||
last = self.last_tracks
|
last = self.last_tracks
|
||||||
for i in xrange(15):
|
for i in xrange(15):
|
||||||
id = self.get_rand_candidate()
|
id = self.get_rand_candidate()
|
||||||
artist = getattr(id, "artist")
|
artist = getattr(id, "artist")[0]
|
||||||
album = getattr(id, "album")
|
album = getattr(id, "album")[0]
|
||||||
title = getattr(id, "title")
|
title = getattr(id, "title")[0]
|
||||||
if (artist, title) in last:
|
if (artist, title) in last:
|
||||||
print "Skipping %s by %s because it has played recently." % (title, artist)
|
print "Skipping %s by %s because it has played recently." % (title, artist)
|
||||||
continue
|
continue
|
||||||
score = getattr(id, "score")
|
score = getattr(id, "score")[0]
|
||||||
if score < 0:
|
if score < 0:
|
||||||
play_anyway = rand.randint(0, 100)
|
play_anyway = rand.randint(0, 100)
|
||||||
if play_anyway < ((20 * score) + 100):
|
if play_anyway < ((20 * score) + 100):
|
||||||
|
|
|
@ -108,8 +108,7 @@ def inc_count(id):
|
||||||
|
|
||||||
def play_id(id):
|
def play_id(id):
|
||||||
libsaria.collection.cur_lib_id = id
|
libsaria.collection.cur_lib_id = id
|
||||||
filepath = get_attr(id, "filepath")
|
libsaria.audio.load(get_attrs(id, "filepath")[0])
|
||||||
libsaria.audio.load(filepath)
|
|
||||||
libsaria.audio.play()
|
libsaria.audio.play()
|
||||||
|
|
||||||
def filter(text):
|
def filter(text):
|
||||||
|
|
|
@ -62,8 +62,7 @@ def lfm_cache_album(file, artist, album):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_artwork_id(id):
|
def get_artwork_id(id):
|
||||||
artist = libsaria.collection.get_attr(id, "artist")
|
artist, album = libsaria.collection.get_attrs(id, "artist", "album")
|
||||||
album = libsaria.collection.get_attr(id, "album")
|
|
||||||
cached = cache[artist]
|
cached = cache[artist]
|
||||||
file = cached.get("%s.jpg" % album, lfm_cache_album, artist, album)
|
file = cached.get("%s.jpg" % album, lfm_cache_album, artist, album)
|
||||||
return file
|
return file
|
||||||
|
|
|
@ -45,16 +45,11 @@ class Collection(gtk.ScrolledWindow):
|
||||||
|
|
||||||
def populate2(self, func):
|
def populate2(self, func):
|
||||||
self.list.freeze()
|
self.list.freeze()
|
||||||
insert = self.list.list.insert
|
insert = self.list.list.insert
|
||||||
getattr = library.get_attr
|
get_attrs = library.get_attrs
|
||||||
ins_next = 0
|
ins_next = 0
|
||||||
for id in func():
|
for id in func():
|
||||||
title = getattr(id, "title")
|
insert(ins_next, get_attrs(id, "id", "title", "lenstr", "artist", "album", "year"))
|
||||||
length = getattr(id, "lenstr")
|
|
||||||
artist = getattr(id, "artist")
|
|
||||||
album = getattr(id, "album")
|
|
||||||
year = getattr(id, "year")
|
|
||||||
insert(ins_next, [id, title, length, artist, album, year])
|
|
||||||
ins_next += 1
|
ins_next += 1
|
||||||
self.list.thaw()
|
self.list.thaw()
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ label = None
|
||||||
image = None
|
image = None
|
||||||
|
|
||||||
lib_get_cur_id = libsaria.collection.lib_get_cur_id
|
lib_get_cur_id = libsaria.collection.lib_get_cur_id
|
||||||
get_attr = libsaria.collection.get_attr
|
get_attrs = libsaria.collection.get_attrs
|
||||||
file_to_id = libsaria.collection.file_to_id
|
file_to_id = libsaria.collection.file_to_id
|
||||||
|
|
||||||
filter = None
|
filter = None
|
||||||
|
@ -74,9 +74,8 @@ class InfoBar(Bar):
|
||||||
|
|
||||||
def change_title(self, filepath):
|
def change_title(self, filepath):
|
||||||
id = file_to_id(filepath)
|
id = file_to_id(filepath)
|
||||||
title = get_attr(id, "title")
|
title, artist = get_attrs(id, "title", "artist")
|
||||||
artist = get_attr(id, "artist")
|
self.title.set_text("%s by %s" % (title, artist))
|
||||||
self.title.set_text("%s by %s" % (title,artist))
|
|
||||||
|
|
||||||
|
|
||||||
class InfoTab(gtk.Notebook):
|
class InfoTab(gtk.Notebook):
|
||||||
|
|
|
@ -8,17 +8,17 @@ libsaria = ocarina.libsaria
|
||||||
|
|
||||||
#update = None
|
#update = None
|
||||||
get_time = None
|
get_time = None
|
||||||
get_attr = None
|
get_attrs = None
|
||||||
file_to_id = None
|
file_to_id = None
|
||||||
|
|
||||||
def set_fns():
|
def set_fns():
|
||||||
#global update
|
#global update
|
||||||
global get_time
|
global get_time
|
||||||
global get_attr
|
global get_attrs
|
||||||
global file_to_id
|
global file_to_id
|
||||||
#update = ocarina.libsaria.audio.get_progress
|
#update = ocarina.libsaria.audio.get_progress
|
||||||
get_time = ocarina.libsaria.audio.get_time
|
get_time = ocarina.libsaria.audio.get_time
|
||||||
get_attr = libsaria.collection.get_attr
|
get_attrs = libsaria.collection.get_attrs
|
||||||
file_to_id = libsaria.collection.file_to_id
|
file_to_id = libsaria.collection.file_to_id
|
||||||
invite("POSTSTART", set_fns)
|
invite("POSTSTART", set_fns)
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ class AttrLabel(gtk.Alignment):
|
||||||
invite("POSTLOAD", self.update)
|
invite("POSTLOAD", self.update)
|
||||||
|
|
||||||
def update(self, filepath):
|
def update(self, filepath):
|
||||||
global get_attr
|
global get_attrs
|
||||||
id = file_to_id(filepath)
|
id = file_to_id(filepath)
|
||||||
if id != None:
|
if id != None:
|
||||||
text = str(get_attr(id, self.attr))
|
text = str(get_attrs(id, self.attr)[0])
|
||||||
if self.other:
|
if self.other:
|
||||||
text = "%s %s" % (self.other, text)
|
text = "%s %s" % (self.other, text)
|
||||||
self.label.set_text(text)
|
self.label.set_text(text)
|
||||||
|
@ -73,7 +73,7 @@ class YearLabel(AttrLabel):
|
||||||
|
|
||||||
class CountLabel(AttrLabel):
|
class CountLabel(AttrLabel):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
AttrLabel.__init__(self, "playcount", "Play count:")
|
AttrLabel.__init__(self, "count", "Play count:")
|
||||||
|
|
||||||
class LengthLabel(AttrLabel):
|
class LengthLabel(AttrLabel):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -7,7 +7,7 @@ gtk = ocarina.gtk
|
||||||
gobject = ocarina.gobject
|
gobject = ocarina.gobject
|
||||||
|
|
||||||
from libsaria.collection import library
|
from libsaria.collection import library
|
||||||
get_attr = library.get_attr
|
get_attrs = library.get_attrs
|
||||||
|
|
||||||
#UNI = gobject.TYPE_UNICHAR
|
#UNI = gobject.TYPE_UNICHAR
|
||||||
|
|
||||||
|
@ -82,24 +82,25 @@ class List(gtk.TreeView):
|
||||||
row = self.get_dest_row_at_pos(x,y)
|
row = self.get_dest_row_at_pos(x,y)
|
||||||
if row == None:
|
if row == None:
|
||||||
return False
|
return False
|
||||||
iter = self.filter_model.get_iter(row[0])#self.list.get_iter(row[0])
|
iter = self.filter_model.get_iter(row[0])
|
||||||
id = self.filter_model[iter][0]
|
id = self.filter_model[iter][0]
|
||||||
|
|
||||||
|
attrs = get_attrs(id, "art", "title", "artist", "album", "year", "lenstr", "count")
|
||||||
|
|
||||||
art = image.Image()
|
art = image.Image()
|
||||||
art.set_from_file(get_attr(id, "art"))
|
art.set_from_file(attrs[0])
|
||||||
art.set_height(52)
|
art.set_height(52)
|
||||||
tip.set_icon(art.get_pixbuf())
|
tip.set_icon(art.get_pixbuf())
|
||||||
|
|
||||||
title = get_attr(id, "title").replace("&", "&")
|
tip.set_markup("<b>%s</b>\nby %s\nfrom %s" %
|
||||||
artist = "by %s" % get_attr(id, "artist").replace("&", "&")
|
(attrs[1].replace("&", "&"),
|
||||||
album = "from %s" % get_attr(id, "album").replace("&", "&")
|
attrs[2].replace("&", "&"),
|
||||||
tip.set_markup("<b>%s</b>\n%s\n%s" % (title, artist, album))
|
attrs[3].replace("&", "&"))
|
||||||
|
)
|
||||||
|
|
||||||
year = "Year: %s" % get_attr(id, "year")
|
|
||||||
length = "Length: %s" % get_attr(id, "lenstr")
|
|
||||||
count = "Play count: %s" % get_attr(id, "playcount")
|
|
||||||
extra = gtk.Label()
|
extra = gtk.Label()
|
||||||
extra.set_markup(" %s\n %s\n %s" % (year, length, count))
|
extra.set_markup(" Year: %s\n Length: %s\n Play count: %s" %
|
||||||
|
(attrs[4], attrs[5], attrs[6]) )
|
||||||
tip.set_custom(extra)
|
tip.set_custom(extra)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import ocarina
|
||||||
gdk = ocarina.gdk
|
gdk = ocarina.gdk
|
||||||
libsaria = ocarina.libsaria
|
libsaria = ocarina.libsaria
|
||||||
file_to_id = libsaria.collection.file_to_id
|
file_to_id = libsaria.collection.file_to_id
|
||||||
get_attr = libsaria.collection.get_attr
|
get_attrs = libsaria.collection.get_attrs
|
||||||
invite = libsaria.event.invite
|
invite = libsaria.event.invite
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ def tweak_icon(file):
|
||||||
def tweak_title(filepath):
|
def tweak_title(filepath):
|
||||||
if filepath != None:
|
if filepath != None:
|
||||||
id = file_to_id(filepath)
|
id = file_to_id(filepath)
|
||||||
title = get_attr(id, "title")
|
title = get_attrs(id, "title")[0]
|
||||||
else:
|
else:
|
||||||
title = ocarina.__vers__
|
title = ocarina.__vers__
|
||||||
ocarina.set_window_title(title)
|
ocarina.set_window_title(title)
|
||||||
|
|
Loading…
Reference in New Issue