From 3eda4225a92a34c9f1d356766f92d3a523b2a75f Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sun, 7 Nov 2010 16:58:01 -0500 Subject: [PATCH] Treeview tooltips The treeview tooltips will show detailed information about the selected track (including album art!) --- ocarina/list.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/ocarina/list.py b/ocarina/list.py index f9a47b2c..e55142ab 100644 --- a/ocarina/list.py +++ b/ocarina/list.py @@ -1,8 +1,13 @@ # Bryan Schumaker (8/15/2010) import ocarina -gtk = ocarina.gtk -gobject = ocarina.gobject +import image +libsaria = ocarina.libsaria +gtk = ocarina.gtk +gobject = ocarina.gobject + +from libsaria.collection import library +get_attr = library.get_attr #UNI = gobject.TYPE_UNICHAR @@ -32,6 +37,7 @@ class List(gtk.TreeView): self.set_rules_hint(True) self.set_tooltip_column(len(cols)-1) + self.set_has_tooltip(True) self.filter_model = self.list.filter_new() self.filter_model.set_visible_func(actions.refilter) @@ -40,6 +46,7 @@ class List(gtk.TreeView): 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) @@ -72,4 +79,29 @@ class List(gtk.TreeView): 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])#self.list.get_iter(row[0]) + id = self.filter_model[iter][0] + + art = image.Image() + art.set_from_file(get_attr(id, "art")) + art.set_height(52) + tip.set_icon(art.get_pixbuf()) + + title = get_attr(id, "title").replace("&", "&") + artist = "by %s" % get_attr(id, "artist").replace("&", "&") + album = "from %s" % get_attr(id, "album").replace("&", "&") + tip.set_markup("%s\n%s\n%s" % (title, artist, album)) + + year = "Year: %s" % get_attr(id, "year") + length = "Length: %s" % get_attr(id, "lenstr") + count = "Play count: %s" % get_attr(id, "playcount") + extra = gtk.Label() + extra.set_markup(" %s\n %s\n %s" % (year, length, count)) + tip.set_custom(extra) + return True +