Use get_attrs

This changes various parts of ocarina / libsaria to use get_attrs()
instead of get_attr().
This commit is contained in:
Bryan Schumaker 2010-11-08 22:18:12 -05:00
parent 7f5d0cd458
commit c5dccdfcdf
9 changed files with 35 additions and 42 deletions

View File

@ -19,7 +19,7 @@ import playlist
file_to_id = library.file_to_id
play_id = library.play_id
get_attr = library.get_attr
get_attrs = library.get_attrs
reset = library.reset
inc_score = library.inc_score
inc_count = library.inc_count

View File

@ -86,17 +86,17 @@ class Playlist(collection.Collection):
def random(self):
if self.size == 0:
return
getattr = libsaria.collection.get_attr
getattr = libsaria.collection.get_attrs
last = self.last_tracks
for i in xrange(15):
id = self.get_rand_candidate()
artist = getattr(id, "artist")
album = getattr(id, "album")
title = getattr(id, "title")
artist = getattr(id, "artist")[0]
album = getattr(id, "album")[0]
title = getattr(id, "title")[0]
if (artist, title) in last:
print "Skipping %s by %s because it has played recently." % (title, artist)
continue
score = getattr(id, "score")
score = getattr(id, "score")[0]
if score < 0:
play_anyway = rand.randint(0, 100)
if play_anyway < ((20 * score) + 100):

View File

@ -108,8 +108,7 @@ def inc_count(id):
def play_id(id):
libsaria.collection.cur_lib_id = id
filepath = get_attr(id, "filepath")
libsaria.audio.load(filepath)
libsaria.audio.load(get_attrs(id, "filepath")[0])
libsaria.audio.play()
def filter(text):

View File

@ -62,8 +62,7 @@ def lfm_cache_album(file, artist, album):
return False
def get_artwork_id(id):
artist = libsaria.collection.get_attr(id, "artist")
album = libsaria.collection.get_attr(id, "album")
artist, album = libsaria.collection.get_attrs(id, "artist", "album")
cached = cache[artist]
file = cached.get("%s.jpg" % album, lfm_cache_album, artist, album)
return file

View File

@ -45,16 +45,11 @@ class Collection(gtk.ScrolledWindow):
def populate2(self, func):
self.list.freeze()
insert = self.list.list.insert
getattr = library.get_attr
ins_next = 0
insert = self.list.list.insert
get_attrs = library.get_attrs
ins_next = 0
for id in func():
title = getattr(id, "title")
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])
insert(ins_next, get_attrs(id, "id", "title", "lenstr", "artist", "album", "year"))
ins_next += 1
self.list.thaw()

View File

@ -11,7 +11,7 @@ label = None
image = None
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
filter = None
@ -74,9 +74,8 @@ class InfoBar(Bar):
def change_title(self, filepath):
id = file_to_id(filepath)
title = get_attr(id, "title")
artist = get_attr(id, "artist")
self.title.set_text("%s by %s" % (title,artist))
title, artist = get_attrs(id, "title", "artist")
self.title.set_text("%s by %s" % (title, artist))
class InfoTab(gtk.Notebook):

View File

@ -8,17 +8,17 @@ libsaria = ocarina.libsaria
#update = None
get_time = None
get_attr = None
get_attrs = None
file_to_id = None
def set_fns():
#global update
global get_time
global get_attr
global get_attrs
global file_to_id
#update = ocarina.libsaria.audio.get_progress
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
invite("POSTSTART", set_fns)
@ -45,10 +45,10 @@ class AttrLabel(gtk.Alignment):
invite("POSTLOAD", self.update)
def update(self, filepath):
global get_attr
global get_attrs
id = file_to_id(filepath)
if id != None:
text = str(get_attr(id, self.attr))
text = str(get_attrs(id, self.attr)[0])
if self.other:
text = "%s %s" % (self.other, text)
self.label.set_text(text)
@ -73,7 +73,7 @@ class YearLabel(AttrLabel):
class CountLabel(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "playcount", "Play count:")
AttrLabel.__init__(self, "count", "Play count:")
class LengthLabel(AttrLabel):
def __init__(self):

View File

@ -7,7 +7,7 @@ gtk = ocarina.gtk
gobject = ocarina.gobject
from libsaria.collection import library
get_attr = library.get_attr
get_attrs = library.get_attrs
#UNI = gobject.TYPE_UNICHAR
@ -82,24 +82,25 @@ class List(gtk.TreeView):
row = self.get_dest_row_at_pos(x,y)
if row == None:
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]
attrs = get_attrs(id, "art", "title", "artist", "album", "year", "lenstr", "count")
art = image.Image()
art.set_from_file(get_attr(id, "art"))
art.set_from_file(attrs[0])
art.set_height(52)
tip.set_icon(art.get_pixbuf())
title = get_attr(id, "title").replace("&", "&amp;")
artist = "by %s" % get_attr(id, "artist").replace("&", "&amp")
album = "from %s" % get_attr(id, "album").replace("&", "&amp;")
tip.set_markup("<b>%s</b>\n%s\n%s" % (title, artist, album))
tip.set_markup("<b>%s</b>\nby %s\nfrom %s" %
(attrs[1].replace("&", "&amp;"),
attrs[2].replace("&", "&amp;"),
attrs[3].replace("&", "&amp;"))
)
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.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)
return True

View File

@ -4,7 +4,7 @@ import ocarina
gdk = ocarina.gdk
libsaria = ocarina.libsaria
file_to_id = libsaria.collection.file_to_id
get_attr = libsaria.collection.get_attr
get_attrs = libsaria.collection.get_attrs
invite = libsaria.event.invite
@ -18,7 +18,7 @@ def tweak_icon(file):
def tweak_title(filepath):
if filepath != None:
id = file_to_id(filepath)
title = get_attr(id, "title")
title = get_attrs(id, "title")[0]
else:
title = ocarina.__vers__
ocarina.set_window_title(title)