diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2013-04-09 20:40:17 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2013-04-09 20:40:17 (GMT) |
commit | 41e065937b31685e96ff70fb39ef50b954c1d863 (patch) | |
tree | f864cdc27b7f2e5731c2cb88f6b47be61c790977 | |
parent | 0909d042fd4f08487fe7de487b8744260a279a10 (diff) |
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 <gonzalo@laptop.org>
https://developer.gnome.org/gtk3/3.8/GtkTreeView.html#GtkTreeView--activate-on-single-click
-rw-r--r-- | controls.py | 1 | ||||
-rw-r--r-- | playlist.py | 14 |
2 files changed, 15 insertions, 0 deletions
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() |