15c4a273bf
The new playlist module can be filtered again.
174 lines
4.3 KiB
Python
174 lines
4.3 KiB
Python
# Bryan Schumaker (8/16/2010)
|
|
|
|
import ocarina
|
|
import list
|
|
import menu
|
|
|
|
libsaria = ocarina.libsaria
|
|
from libsaria import collection
|
|
library = collection.library
|
|
playlist = collection.playlist
|
|
|
|
event = ocarina.libsaria.event
|
|
gtk = ocarina.gtk
|
|
|
|
|
|
class Actions:
|
|
def __init__(self):
|
|
self.mouse_motion = None
|
|
self.selected_row = None
|
|
self.refilter = None
|
|
self.show_rc_menu = 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 populate2(self, func):
|
|
self.list.freeze()
|
|
insert = self.list.list.insert
|
|
getattr = library.get_attr
|
|
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, ""])
|
|
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]
|
|
items = self.mouse_motion(list_row)
|
|
list.set_value(list_iter, len(list_row)-1,
|
|
"Played: %s Score: %s" % items)
|
|
|
|
def add_selected_to_playlist(self, *args):
|
|
self.list.for_each_selected(playlist.add_id)
|
|
playlist.save()
|
|
collection.plist_refresh()
|
|
|
|
|
|
class Library(Collection):
|
|
def __init__(self):
|
|
actions = Actions()
|
|
actions.mouse_motion = self.mouse_motion
|
|
actions.selected_row = self.select_row
|
|
actions.refilter = self.refilter
|
|
actions.show_rc_menu = menu.make_lib_menu
|
|
|
|
Collection.__init__(self, actions)
|
|
libsaria.event.invite("POSTSTART", self.populate, bg=True)
|
|
libsaria.event.invite("POSTNEWSOURCE", self.refresh, bg=True)
|
|
|
|
menu.add_lib_menu_item("Add to playlist", self.add_selected_to_playlist)
|
|
|
|
def populate(self):
|
|
#import datetime
|
|
#before = datetime.datetime.now()
|
|
Collection.populate(self, library.walk_tags)
|
|
#after = datetime.datetime.now()
|
|
#print "Populating took: %s" % (after - before)
|
|
|
|
def refresh(self, arg):
|
|
self.clear()
|
|
self.populate()
|
|
|
|
def reset(self):
|
|
collection.reset()
|
|
self.clear()
|
|
|
|
def mouse_motion(self, row):
|
|
return (collection.get_attr(row[0], "playcount"),
|
|
collection.get_attr(row[0], "score"))
|
|
|
|
def select_row(self, row):
|
|
collection.change_score()
|
|
collection.play_id(row[0])
|
|
collection.inc_score(row[0], 1)
|
|
|
|
def filter(self, text):
|
|
library.filter(text)
|
|
self.list.refilter()
|
|
|
|
def refilter(self, list, iter):
|
|
return library.is_visible(list[iter][0])
|
|
|
|
|
|
class Playlist(Collection):
|
|
def __init__(self):
|
|
actions = Actions()
|
|
actions.mouse_motion = self.mouse_motion
|
|
actions.selected_row = self.select_row
|
|
actions.refilter = self.refilter
|
|
actions.show_rc_menu = menu.make_plist_menu
|
|
|
|
Collection.__init__(self, actions)
|
|
libsaria.event.invite("POSTSTART", self.populate, bg=True)
|
|
libsaria.event.invite("PREPLISTREFRESH", self.refresh)
|
|
|
|
def refresh(self, arg=None):
|
|
self.clear()
|
|
self.populate()
|
|
|
|
def reset(self):
|
|
playlist.reset()
|
|
playlist.save()
|
|
self.clear()
|
|
|
|
def populate(self):
|
|
#import datetime
|
|
#before = datetime.datetime.now()
|
|
#Collection.populate(self, collection.walk_plist)
|
|
Collection.populate2(self, playlist.walk)
|
|
#after = datetime.datetime.now()
|
|
#print "Populating took: %s" % (after - before)
|
|
|
|
def mouse_motion(self, row):
|
|
return (collection.get_attr(row[0], "playcount"),
|
|
collection.get_attr(row[0], "score"))
|
|
|
|
def select_row(self, row):
|
|
collection.change_score()
|
|
collection.play_id(row[0])
|
|
collection.inc_score(row[0], 1)
|
|
|
|
def filter(self, text):
|
|
playlist.filter(text)
|
|
self.list.refilter()
|
|
|
|
def refilter(self, list, iter):
|
|
return playlist.is_visible(list[iter][0])
|