Collection get_attr() and list hover popup

Collections now have a get_attr function.  This function takes a song id
and a string with the requested attribute.  The value of the attribute
is returned.  This is used for generating a hover popup with the
playcount.
This commit is contained in:
Bryan Schumaker 2010-08-20 19:37:55 -04:00
parent 304855c10d
commit 8594c3b330
5 changed files with 35 additions and 8 deletions

View File

@ -29,3 +29,8 @@ def walk_library():
for track in library:
yield track
def lib_get_attr(id, attr):
global library
return library.get_attr(id, attr)

View File

@ -18,6 +18,13 @@ class Collection:
for track in self.tree.walk():
yield track
def get_attr(self, id, attr):
node = self.tree
tags = self.table[id]
for tag in tags:
node = node[tag]
return node[attr]
def scan(self, path):
print "Scanning path:", path
global ins_table
@ -51,7 +58,6 @@ class Collection:
return
(self.table, self.index, self.tree) = objects
def insert(self, file, filepath):
global tag
global audio

View File

@ -28,7 +28,6 @@ class Tree(dict):
def walk(self):
keys = self.keys()
keys.sort()
keys.reverse()
get_item = self.__getitem__
for key in keys:
for track in get_item(key).walk():

View File

@ -12,32 +12,46 @@ gtk = ocarina.gtk
class Collection(gtk.ScrolledWindow):
def __init__(self):
def __init__(self, mouse_motion):
gtk.ScrolledWindow.__init__(self)
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.list = list.List()
self.list.connect("motion-notify-event", self.on_mouse_motion)
self.mouse_motion = mouse_motion
self.add(self.list)
self.show()
def populate(self, func):
self.list.freeze()
insert = self.list.list.insert
ins_next = 0
for track in func():
get = track.__getitem__
insert(0, [get("id"),
insert(ins_next, [get("id"),
get("title"),
get("length"),
get("artist"),
get("album"),
get("year"),
get("playcount")])
get("year"), ""])
ins_next += 1
self.list.thaw()
def on_mouse_motion(self, widget, pos):
list = self.list
x,y = list.convert_bin_window_to_widget_coords(int(pos.x), int(pos.y))
row = list.get_dest_row_at_pos(x,y)
list = list.list
if row is not None:
row = row[0]
list_iter = list.get_iter(row)
list_row = list[list_iter]
string = self.mouse_motion(list_row)
list.set_value(list_iter, len(list_row)-1, "Played: %s"%string)
class Library(Collection):
def __init__(self):
Collection.__init__(self)
Collection.__init__(self, self.mouse_motion)
libsaria.event.invite("POSTSTART", self.populate, bg=True)
def populate(self):
@ -46,3 +60,6 @@ class Library(Collection):
Collection.populate(self, collection.walk_library)
after = datetime.datetime.now()
print "Populating took: %s" % (after-before)
def mouse_motion(self, row):
return collection.lib_get_attr(row[0], "playcount")

View File

@ -9,7 +9,7 @@ gobject = ocarina.gobject
class List(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.list = gtk.ListStore(int, str, str, str, str, int, int)
self.list = gtk.ListStore(int, str, str, str, str, int, str)
self.append = self.list.append
cell = gtk.CellRendererText()