ocarina/ocarina/list.py
Bryan Schumaker 02fe6dc8ba Right click menus
I have started a system to create a right click menu on the fly and show
it.  Currently, it only works for the library.  This will be used to
populate the playlist and probably many other things (like plugins!)
2010-10-20 21:11:12 -04:00

76 lines
1.9 KiB
Python

# Bryan Schumaker (8/15/2010)
import ocarina
gtk = ocarina.gtk
gobject = ocarina.gobject
#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, str)
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_tooltip_column(len(cols)-1)
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("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])