From 3a73e954c4617dd691c7eb34225af3c00462771f Mon Sep 17 00:00:00 2001 From: Sai Vineet Date: Sun, 24 Nov 2013 15:34:50 +0000 Subject: Add reorder capability to Jukebox Problem: Playlist songs can't be reordered once added. There is a need of a reordering system. Solution: Make a reorder system like Chart Activity has. Fixes #4484 --- diff --git a/activity.py b/activity.py index a450898..dc996ee 100644 --- a/activity.py +++ b/activity.py @@ -35,6 +35,7 @@ from sugar3.activity.widgets import ActivityToolbarButton from sugar3.graphics.alert import ErrorAlert from sugar3.graphics.alert import Alert from sugar3.graphics.icon import Icon +from sugar3.graphics.toolbutton import ToolButton import gi gi.require_version('Gtk', '3.0') @@ -110,6 +111,8 @@ class JukeboxActivity(activity.Activity): self._video_canvas = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + self._playlist_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.playlist_widget = PlayList() self.playlist_widget.connect('play-index', self.__play_index_cb) self.playlist_widget.connect('missing-tracks', @@ -117,7 +120,29 @@ class JukeboxActivity(activity.Activity): self.playlist_widget.set_size_request( Gdk.Screen.width() * PLAYLIST_WIDTH_PROP, 0) self.playlist_widget.show() - self._video_canvas.pack_start(self.playlist_widget, False, True, 0) + + self._playlist_box.pack_start(self.playlist_widget, expand=True, + fill=True, padding=0) + + self._playlist_toolbar = Gtk.Toolbar() + + move_up = ToolButton("go-up") + move_up.set_tooltip(_("Move up")) + move_up.connect("clicked", self._move_up_cb) + move_up.show() + self._playlist_toolbar.insert(move_up, 0) + + move_down = ToolButton("go-down") + move_down.set_tooltip(_("Move down")) + move_down.connect("clicked", self._move_down_cb) + move_down.show() + self._playlist_toolbar.insert(move_down, 1) + + self._playlist_toolbar.show() + + self._playlist_box.pack_end(self._playlist_toolbar, False, False, 0) + self._playlist_box.show() + self._video_canvas.pack_start(self._playlist_box, False, False, 0) # Create the player just once logging.debug('Instantiating GstPlayer') @@ -165,6 +190,12 @@ class JukeboxActivity(activity.Activity): Gdk.Screen.get_default().connect('size-changed', self._configure_cb) + def _move_up_cb(self, button): + self.playlist_widget.move_up() + + def _move_down_cb(self, button): + self.playlist_widget.move_down() + def _configure_cb(self, event=None): self._toolbar_box.toolbar.remove(self._stop) self._toolbar_box.toolbar.remove(self._separator) @@ -431,9 +462,9 @@ class JukeboxActivity(activity.Activity): def __toggle_playlist_cb(self, toolbar): if self._view_toolbar._show_playlist.get_active(): - self.playlist_widget.show_all() + self._playlist_box.show_all() else: - self.playlist_widget.hide() + self._playlist_box.hide() self._video_canvas.queue_draw() diff --git a/playlist.py b/playlist.py index 26e8f75..26474fd 100644 --- a/playlist.py +++ b/playlist.py @@ -49,8 +49,8 @@ class PlayList(Gtk.ScrolledWindow): self.listview = Gtk.TreeView() self.treemodel = Gtk.ListStore(int, object, bool) self.listview.set_model(self.treemodel) - selection = self.listview.get_selection() - selection.set_mode(Gtk.SelectionMode.SINGLE) + self.selection = self.listview.get_selection() + self.selection.set_mode(Gtk.SelectionMode.SINGLE) renderer_icon = CellRendererIcon(self.listview) renderer_icon.props.icon_name = 'emblem-notification' @@ -83,6 +83,39 @@ class PlayList(Gtk.ScrolledWindow): self.add(self.listview) + def move_up(self): + selected_iter = self.selection.get_selected()[1] + position = self.treemodel.get_iter(int(str(self.treemodel.get_path( + selected_iter))) - 1) + self.treemodel.move_before(selected_iter, position) + self._items[self._current_playing - 1], \ + self._items[self._current_playing] = \ + self._items[self._current_playing], \ + self._items[self._current_playing - 1] + index = 0 + for tree_item, playlist_item in zip(self.treemodel, self._items): + tree_item[0] = index + index = index + 1 + + self._current_playing -= 1 + + def move_down(self): + selected_iter = self.selection.get_selected()[1] + position = self.treemodel.get_iter(int(str(self.treemodel.get_path( + selected_iter))) + 1) + self.treemodel.move_after(selected_iter, position) + self._items[self._current_playing + 1], \ + self._items[self._current_playing] = \ + self._items[self._current_playing], \ + self._items[self._current_playing + 1] + + index = 0 + for tree_item, playlist_item in zip(self.treemodel, self._items): + tree_item[0] = index + index = index + 1 + + self._current_playing += 1 + def __on_cursor_changed(self, treeview): selection = self.listview.get_selection() sel_model, sel_rows = self.listview.get_selection().get_selected_rows() @@ -116,7 +149,7 @@ class PlayList(Gtk.ScrolledWindow): def _set_number(self, column, cell, model, it, data): idx = model.get_value(it, COLUMNS['index']) - cell.set_property('text', idx + 1) + cell.set_property('text', str(idx + 1)) def _set_title(self, column, cell, model, it, data): title = model.get_value(it, COLUMNS['title']) -- cgit v0.9.1