# Bryan Schumaker (8/16/2010) import ocarina import list libsaria = ocarina.libsaria from libsaria import collection event = ocarina.libsaria.event gtk = ocarina.gtk class Collection(gtk.ScrolledWindow): def __init__(self, mouse_motion, select): 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.list.connect("row-activated", self.row_activated) self.mouse_motion = mouse_motion self.selected_row = select 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(ins_next, [get("id"), get("title"), get("length"), get("artist"), get("album"), 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) def row_activated(self, widget, path, column): list = self.list.list iter = list.get_iter(path) row = list[iter] self.selected_row(row) class Library(Collection): def __init__(self): Collection.__init__(self, self.mouse_motion, self.select_row) libsaria.event.invite("POSTSTART", self.populate, bg=True) def populate(self): import datetime before = datetime.datetime.now() 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") def select_row(self, row): collection.lib_play_id(row[0])