108 lines
2.8 KiB
Python
108 lines
2.8 KiB
Python
# Bryan Schumaker (8/15/2010)
|
|
|
|
import ocarina
|
|
import image
|
|
libsaria = ocarina.libsaria
|
|
gtk = ocarina.gtk
|
|
gobject = ocarina.gobject
|
|
|
|
from libsaria.sources import library
|
|
get_attrs = library.get_attrs
|
|
|
|
#UNI = gobject.TYPE_UNICHAR
|
|
|
|
class List(gtk.TreeView):
|
|
def __init__(self, actions):
|
|
gtk.TreeView.__init__(self)
|
|
self.actions = actions
|
|
self.list = gtk.ListStore(int, str, str, str, str, int)
|
|
|
|
self.append = self.list.append
|
|
|
|
cell = gtk.CellRendererText()
|
|
cell.set_fixed_height_from_font(1)
|
|
|
|
cols = ["Id", "Title", "Length", "Artist", "Album", "Year", "Played"]
|
|
colw = [ 2, 300, 60, 125, 125, 50, 70]
|
|
for index, label in enumerate(cols):
|
|
col = gtk.TreeViewColumn(label, cell)
|
|
col.add_attribute(cell, 'text', index)
|
|
col.set_resizable(True)
|
|
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
|
col.set_min_width(2)
|
|
col.set_max_width(700)
|
|
col.set_fixed_width(colw[index])
|
|
if label!="Id" and label!="Played":
|
|
self.append_column(col)
|
|
|
|
self.set_rules_hint(True)
|
|
self.set_has_tooltip(True)
|
|
|
|
self.filter_model = self.list.filter_new()
|
|
self.filter_model.set_visible_func(actions.refilter)
|
|
self.refilter = self.filter_model.refilter
|
|
|
|
self.sel = self.get_selection()
|
|
self.sel.set_mode(gtk.SELECTION_MULTIPLE)
|
|
|
|
self.connect("query-tooltip", self.query_tooltip)
|
|
self.connect("row-activated", self.row_activated)
|
|
self.connect("button-release-event", self.button_clicked)
|
|
|
|
self.set_model(self.filter_model)
|
|
self.show_all()
|
|
|
|
def button_clicked(self, widget, event):
|
|
if event.button == 3:
|
|
self.actions.show_rc_menu(event.button, event.time)
|
|
|
|
def row_activated(self, widget, path, column):
|
|
list = self.filter_model
|
|
iter = list.get_iter(path)
|
|
row = list[iter]
|
|
self.actions.selected_row(row)
|
|
|
|
def freeze(self):
|
|
self.set_model(None)
|
|
self.freeze_child_notify()
|
|
|
|
def thaw(self):
|
|
self.set_model(self.filter_model)
|
|
self.thaw_child_notify()
|
|
|
|
def clear(self):
|
|
self.list.clear()
|
|
|
|
def for_each_selected(self, func):
|
|
filter = self.filter_model
|
|
for iter in self.sel.get_selected_rows()[1]:
|
|
func(filter[iter][0])
|
|
|
|
def query_tooltip(self, widget, x, y, keyboard, tip):
|
|
row = self.get_dest_row_at_pos(x,y)
|
|
if row == None:
|
|
return False
|
|
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(attrs[0])
|
|
art.set_height(52)
|
|
tip.set_icon(art.get_pixbuf())
|
|
|
|
tip.set_markup("<b>%s</b>\nby %s\nfrom %s" %
|
|
(attrs[1].replace("&", "&"),
|
|
attrs[2].replace("&", "&"),
|
|
attrs[3].replace("&", "&"))
|
|
)
|
|
|
|
extra = gtk.Label()
|
|
extra.set_markup(" Year: %s\n Length: %s\n Play count: %s" %
|
|
(attrs[4], attrs[5], attrs[6]) )
|
|
tip.set_custom(extra)
|
|
return True
|
|
|
|
|