From 41e065937b31685e96ff70fb39ef50b954c1d863 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Tue, 09 Apr 2013 20:40:17 +0000 Subject: Set the right playing item when click over one item in the playlist As the treeview trigger 'row-activated' on double-click (a property to activate on single click was added in Gtk 3.8, but we don't have it yet), and all in Sugar is selected on single click, added the code to set the playing item on 'cursor-changed' signal too. Signed-off-by: Gonzalo Odiard https://developer.gnome.org/gtk3/3.8/GtkTreeView.html#GtkTreeView--activate-on-single-click --- diff --git a/controls.py b/controls.py index 4655144..011406d 100644 --- a/controls.py +++ b/controls.py @@ -212,6 +212,7 @@ class Controls(GObject.GObject): self.activity.player.pause() self.set_button_play() GObject.source_remove(self._scale_update_id) + self._scale_update_id = -1 else: if self.activity.player.error: self.set_disabled() diff --git a/playlist.py b/playlist.py index 123effb..26e8f75 100644 --- a/playlist.py +++ b/playlist.py @@ -79,8 +79,22 @@ class PlayList(Gtk.ScrolledWindow): self.listview.set_enable_search(False) self.listview.connect('row-activated', self.__on_row_activated) + self.listview.connect('cursor-changed', self.__on_cursor_changed) + self.add(self.listview) + def __on_cursor_changed(self, treeview): + selection = self.listview.get_selection() + sel_model, sel_rows = self.listview.get_selection().get_selected_rows() + for row in sel_rows: + index = sel_model.get_value(sel_model.get_iter(row), 0) + if index != self._current_playing: + path = self._items[index]['path'] + available = self._items[index]['available'] + if available: + self.set_current_playing(index) + self.emit('play-index', index, path) + def __on_row_activated(self, treeview, path, col): model = treeview.get_model() -- cgit v0.9.1