[Sugar-devel] [PATCH Jukebox] Subtoolbar with "Clear" and "Remove" buttons SL #3357

Manuel Kaufmann humitos at gmail.com
Tue Jun 5 18:14:21 EDT 2012


There is a new Toolbar that contains "Clear Playlist" and
"Remove selected track(s) from the playlist" buttons.

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 icons/edit-clear.svg |    7 +++++++
 jukeboxactivity.py   |   40 ++++++++++++++++++++++++++++++++++++++++
 widgets.py           |   12 ++++++++++++
 3 files changed, 59 insertions(+)
 create mode 100644 icons/edit-clear.svg

diff --git a/icons/edit-clear.svg b/icons/edit-clear.svg
new file mode 100644
index 0000000..edbe99f
--- /dev/null
+++ b/icons/edit-clear.svg
@@ -0,0 +1,7 @@
+<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 1.1//EN'  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+	<!ENTITY stroke_color "#010101">
+	<!ENTITY fill_color "#FFFFFF">
+]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="edit-clear">
+	<path d="M5,10.033v34.934h45V10.033H5z M37.575,35.1c0.684,0.683,0.684,1.793,0,2.476   c-0.341,0.342-0.789,0.513-1.237,0.513s-0.896-0.171-1.238-0.513l-7.601-7.602l-7.602,7.602c-0.342,0.342-0.79,0.513-1.237,0.513   s-0.895-0.171-1.237-0.513c-0.684-0.683-0.684-1.793,0-2.476l7.601-7.601l-7.601-7.602c-0.684-0.684-0.684-1.791,0-2.474   c0.683-0.684,1.791-0.684,2.474,0l7.602,7.601l7.601-7.601c0.683-0.684,1.793-0.684,2.476,0c0.684,0.683,0.684,1.791,0,2.474   l-7.602,7.602L37.575,35.1z" fill="&fill_color;"/>
+</g></svg>
+
diff --git a/jukeboxactivity.py b/jukeboxactivity.py
index cc277b7..1766b40 100644
--- a/jukeboxactivity.py
+++ b/jukeboxactivity.py
@@ -33,6 +33,7 @@ from sugar.datastore import datastore
 
 OLD_TOOLBAR = False
 try:
+    from sugar.graphics.toolbutton import ToolButton
     from sugar.graphics.toolbarbox import ToolbarBox
     from sugar.graphics.toolbarbox import ToolbarButton
     from sugar.activity.widgets import StopButton
@@ -89,6 +90,19 @@ class JukeboxActivity(activity.Activity):
             toolbox.add_toolbar(_('View'), _view_toolbar)
             _view_toolbar.show()
 
+            _playlist_toolbar = gtk.Toolbar()
+            erase_playlist_entry = ToolButton(icon_name='edit-delete')
+            erase_playlist_entry.connect('clicked',
+                                         self._erase_playlist_entry_clicked_cb)
+            _playlist_toolbar.insert(erase_playlist_entry, -1)
+
+            clear_playlist = ToolButton(icon_name='edit-clear')
+            clear_playlist.connect('clicked', self._clear_playlist_clicked_cb)
+            _playlist_toolbar.insert(clear_playlist, -1)
+            _playlist_toolbar.show_all()
+
+            toolbox.add_toolbar(_('Playlist'), _playlist_toolbar)
+
             toolbox.show()
 
             toolbar.grab_focus()
@@ -120,6 +134,25 @@ class JukeboxActivity(activity.Activity):
             toolbar_box.toolbar.insert(view_toolbar_button, -1)
             view_toolbar_button.show()
 
+            _playlist_toolbar = gtk.Toolbar()
+            erase_playlist_entry = ToolButton(icon_name='edit-delete')
+            erase_playlist_entry.set_tooltip(_('Remove selected track(s)' \
+                                                   ' from the playlist'))
+            erase_playlist_entry.connect('clicked',
+                                         self._erase_playlist_entry_clicked_cb)
+            _playlist_toolbar.insert(erase_playlist_entry, -1)
+
+            clear_playlist = ToolButton(icon_name='edit-clear')
+            clear_playlist.set_tooltip(_('Clear Playlist'))
+            clear_playlist.connect('clicked', self._clear_playlist_clicked_cb)
+            _playlist_toolbar.insert(clear_playlist, -1)
+            _playlist_toolbar.show_all()
+
+            playlist_toolbar_button = ToolbarButton(
+                page=_playlist_toolbar,
+                icon_name='view-source')
+            toolbar_box.toolbar.insert(playlist_toolbar_button, -1)
+
             self.control = Control(toolbar_box.toolbar, self)
 
             separator = gtk.SeparatorToolItem()
@@ -573,6 +606,13 @@ class JukeboxActivity(activity.Activity):
 
         return True
 
+    def _erase_playlist_entry_clicked_cb(self, widget):
+        self.playlist_widget.delete_selected_items()
+
+    def _clear_playlist_clicked_cb(self, widget):
+        self.playlist = []
+        self.playlist_widget.clear()
+
     def __go_fullscreen_cb(self, toolbar):
         self.fullscreen()
 
diff --git a/widgets.py b/widgets.py
index 67c5bc4..8befd9e 100644
--- a/widgets.py
+++ b/widgets.py
@@ -85,3 +85,15 @@ class PlayListWidget(gtk.ScrolledWindow):
 
     def set_cursor(self, index):
         self.listview.set_cursor((index,))
+
+    def clear(self):
+        self.treemodel.clear()
+        self._playlist = None
+
+    def delete_selected_items(self):
+        selection = self.listview.get_selection()
+        sel_model, sel_rows = self.listview.get_selection().get_selected_rows()
+        for row in sel_rows:
+            self._playlist.pop(row[0])
+            self.treemodel.remove(self.treemodel.get_iter(row))
+        self.update(self._playlist)
-- 
1.7.10.2



More information about the Sugar-devel mailing list