93 lines
2.3 KiB
Python
93 lines
2.3 KiB
Python
# Bryan Schumaker (8/16/2010)
|
|
|
|
import ocarina
|
|
import list
|
|
|
|
|
|
libsaria = ocarina.libsaria
|
|
from libsaria import collection
|
|
|
|
event = ocarina.libsaria.event
|
|
gtk = ocarina.gtk
|
|
|
|
|
|
class Actions:
|
|
def __init__(self):
|
|
self.mouse_motion = None
|
|
self.selected_row = None
|
|
self.refilter = None
|
|
|
|
|
|
class Collection(gtk.ScrolledWindow):
|
|
def __init__(self, actions):
|
|
gtk.ScrolledWindow.__init__(self)
|
|
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
self.list = list.List(actions)
|
|
|
|
self.list.connect("motion-notify-event", self.on_mouse_motion)
|
|
self.mouse_motion = actions.mouse_motion
|
|
self.selected_row = actions.selected_row
|
|
|
|
self.add(self.list)
|
|
self.show()
|
|
|
|
def clear(self):
|
|
self.list.clear()
|
|
|
|
def populate(self, func):
|
|
self.list.freeze()
|
|
insert = self.list.list.insert
|
|
ins_next = 0
|
|
for track in func():
|
|
insert(ins_next, [track[3], track[2],
|
|
track[5], track[0], track[1], track[4], ""])
|
|
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):
|
|
actions = Actions()
|
|
actions.mouse_motion = self.mouse_motion
|
|
actions.selected_row = self.select_row
|
|
actions.refilter = self.refilter
|
|
Collection.__init__(self, actions)
|
|
libsaria.event.invite("POSTSTART", self.populate, bg=True)
|
|
libsaria.event.invite("POSTNEWSOURCE", self.refresh, 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 refresh(self, arg):
|
|
self.clear()
|
|
self.populate()
|
|
|
|
def mouse_motion(self, row):
|
|
return collection.lib_get_attr(row[0], "playcount")
|
|
|
|
def select_row(self, row):
|
|
collection.lib_play_id(row[0])
|
|
|
|
def filter(self, text):
|
|
collection.lib_filter(text)
|
|
self.list.refilter()
|
|
|
|
def refilter(self, list, iter):
|
|
return collection.lib_is_visible(list[iter][0])
|