diff --git a/ocarina/collection.py b/ocarina/collection.py index 863b7d33..890752e4 100644 --- a/ocarina/collection.py +++ b/ocarina/collection.py @@ -11,16 +11,22 @@ 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, mouse_motion, select, refilter): + def __init__(self, actions): gtk.ScrolledWindow.__init__(self) self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - self.list = list.List(refilter) + self.list = list.List(actions) 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.mouse_motion = actions.mouse_motion + self.selected_row = actions.selected_row self.add(self.list) self.show() @@ -50,17 +56,14 @@ class Collection(gtk.ScrolledWindow): 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.filter_model - 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, - self.refilter) + 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) @@ -79,7 +82,6 @@ class Library(Collection): return collection.lib_get_attr(row[0], "playcount") def select_row(self, row): - print row[0], row[1] collection.lib_play_id(row[0]) def filter(self, text): diff --git a/ocarina/list.py b/ocarina/list.py index 2064d1bb..eb025789 100644 --- a/ocarina/list.py +++ b/ocarina/list.py @@ -7,12 +7,12 @@ gobject = ocarina.gobject #UNI = gobject.TYPE_UNICHAR class List(gtk.TreeView): - def __init__(self, refilter): + 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 - self.set_visible = refilter cell = gtk.CellRendererText() cell.set_fixed_height_from_font(1) @@ -34,12 +34,20 @@ class List(gtk.TreeView): self.set_tooltip_column(len(cols)-1) self.filter_model = self.list.filter_new() - self.filter_model.set_visible_func(self.set_visible) + self.filter_model.set_visible_func(actions.refilter) self.refilter = self.filter_model.refilter + self.connect("row-activated", self.row_activated) + self.set_model(self.filter_model) self.show_all() + 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)