[Sugar-devel] [PATCH Jukebox] Show 'No media' message when Jukebox starts from scratch

Manuel Kaufmann humitos at gmail.com
Mon Nov 5 10:41:44 EST 2012


When the user starts a new instance of Jukebox the 'No media' message
is shown with a button to 'Choose media files' that opens the Object
Chooser.

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 emptypanel.py              | 45 +++++++++++++++++++++++++++++++++++++++++++++
 icons/activity-jukebox.svg |  7 +++++++
 jukeboxactivity.py         | 35 +++++++++++++++++++++++------------
 3 files changed, 75 insertions(+), 12 deletions(-)
 create mode 100644 emptypanel.py
 create mode 100644 icons/activity-jukebox.svg

diff --git a/emptypanel.py b/emptypanel.py
new file mode 100644
index 0000000..d8fa042
--- /dev/null
+++ b/emptypanel.py
@@ -0,0 +1,45 @@
+import logging
+
+from gi.repository import Gtk
+
+from sugar3.graphics import style
+from sugar3.graphics.icon import Icon
+
+
+def show(activity, icon_name, message, btn_label, btn_callback):
+    empty_widgets = Gtk.EventBox()
+    empty_widgets.modify_bg(Gtk.StateType.NORMAL,
+                            style.COLOR_WHITE.get_gdk_color())
+
+    vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+    mvbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+    vbox.pack_start(mvbox, True, False, 0)
+
+    image_icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
+                      icon_name=icon_name,
+                      stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
+                      fill_color=style.COLOR_TRANSPARENT.get_svg())
+    mvbox.pack_start(image_icon, False, False, style.DEFAULT_PADDING)
+
+    label = Gtk.Label('<span foreground="%s"><b>%s</b></span>' %
+                      (style.COLOR_BUTTON_GREY.get_html(),
+                       message))
+    label.set_use_markup(True)
+    mvbox.pack_start(label, False, False, style.DEFAULT_PADDING)
+
+    hbox = Gtk.Box()
+    open_image_btn = Gtk.Button()
+    open_image_btn.connect('clicked', btn_callback)
+    add_image = Gtk.Image.new_from_stock(Gtk.STOCK_ADD,
+                                         Gtk.IconSize.BUTTON)
+    buttonbox = Gtk.Box()
+    buttonbox.pack_start(add_image, False, True, 0)
+    buttonbox.pack_end(Gtk.Label(btn_label), True, True, 5)
+    open_image_btn.add(buttonbox)
+    hbox.pack_start(open_image_btn, True, False, 0)
+    mvbox.pack_start(hbox, False, False, style.DEFAULT_PADDING)
+
+    empty_widgets.add(vbox)
+    empty_widgets.show_all()
+    logging.error('Showing empty Panel')
+    activity.set_canvas(empty_widgets)
diff --git a/icons/activity-jukebox.svg b/icons/activity-jukebox.svg
new file mode 100644
index 0000000..b921d4f
--- /dev/null
+++ b/icons/activity-jukebox.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="activity-jukebox">
+	<path d="M17.666,7.884v32.841   c-2.587-0.614-7.914-0.612-10.755,1.764c-5.688,4.76-0.695,10.109,5.815,7.456c3.705-1.512,4.94-3.937,4.94-7.597V25.997   l30.952-3.516v12.974c-4.212-0.615-7.915-0.614-10.758,1.764c-5.688,4.76-0.695,10.109,5.815,7.454   c3.705-1.51,4.942-3.936,4.942-7.596V4.293L17.666,7.884z M48.618,15.86l-30.952,4.029l0-5.225l30.953-4.102V15.86z" display="inline" fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5"/>
+</g></svg>
+
diff --git a/jukeboxactivity.py b/jukeboxactivity.py
index 1bc4d4a..bde15a3 100644
--- a/jukeboxactivity.py
+++ b/jukeboxactivity.py
@@ -24,6 +24,7 @@
 import sys
 import logging
 import tempfile
+import emptypanel
 from gettext import gettext as _
 import os
 
@@ -152,31 +153,34 @@ class JukeboxActivity(activity.Activity):
         # self.bin = Gtk.HBox()
         # self.bin.show()
 
-        self.canvas = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
+        self._video_canvas = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
         self._alert = None
 
         self.playlist_widget = PlayListWidget(self.play)
         self.playlist_widget.update(self.playlist)
         self.playlist_widget.show()
-        self.canvas.pack_start(self.playlist_widget, False, True, 0)
+        self._video_canvas.pack_start(self.playlist_widget, False, True, 0)
         self._empty_widget = Gtk.Label(label="")
         self._empty_widget.show()
         self.videowidget = VideoWidget()
-        self.set_canvas(self.canvas)
+        self.set_canvas(self._video_canvas)
         self._init_view_area()
         self.show_all()
-        self.canvas.connect('size-allocate', self.__size_allocate_cb)
+        self._video_canvas.connect('size-allocate', self.__size_allocate_cb)
 
-        #From ImageViewer Activity
         self._want_document = True
         if self._object_id is None:
-            self._show_object_picker = GObject.timeout_add(1000, \
-            self._show_picker_cb)
+            emptypanel.show(self, 'activity-jukebox',
+                            _('No media'), _('Choose media files'),
+                            self._show_picker_cb)
+        else:
+            self._init_gstplayer()
 
         if handle.uri:
             self.uri = handle.uri
             GObject.idle_add(self._start, self.uri, handle.title)
 
+    def _init_gstplayer(self):
         # Create the player just once
         logging.debug('Instantiating GstPlayer')
         self.player = GstPlayer(self.videowidget)
@@ -205,7 +209,7 @@ class JukeboxActivity(activity.Activity):
         self.view_area.set_show_tabs(False)
         self.view_area.append_page(self._empty_widget, None)
         self.view_area.append_page(self.videowidget, None)
-        self.canvas.pack_end(self.view_area, expand=True,
+        self._video_canvas.pack_end(self.view_area, expand=True,
                              fill=True, padding=0)
 
     def _switch_canvas(self, show_video):
@@ -219,10 +223,10 @@ class JukeboxActivity(activity.Activity):
             self.view_area.set_current_page(1)
         else:
             self.view_area.set_current_page(0)
-        self.canvas.queue_draw()
+        self._video_canvas.queue_draw()
 
     def __size_allocate_cb(self, widget, allocation):
-        canvas_size = self.canvas.get_allocation()
+        canvas_size = self._video_canvas.get_allocation()
         playlist_width = int(canvas_size.width * PLAYLIST_WIDTH_PROP)
         self.playlist_widget.set_size_request(playlist_width, 0)
 
@@ -380,7 +384,7 @@ class JukeboxActivity(activity.Activity):
         logging.debug("shared start")
         pass
 
-    def _show_picker_cb(self):
+    def _show_picker_cb(self, button=None):
         #From ImageViewer Activity
         if not self._want_document:
             return
@@ -403,6 +407,13 @@ class JukeboxActivity(activity.Activity):
                     title = jobject.metadata.get('title', None)
                     self._load_file(jobject.file_path, title,
                             jobject.object_id)
+
+                    if button is not None:
+                        # called from the "Choose media files" button
+                        # from EmptyPanel
+                        self.set_canvas(self._video_canvas)
+                        self._init_gstplayer()
+
         finally:
             #chooser.destroy()
             #del chooser
@@ -654,7 +665,7 @@ class JukeboxActivity(activity.Activity):
             self.playlist_widget.hide()
         else:
             self.playlist_widget.show_all()
-        self.canvas.queue_draw()
+        self._video_canvas.queue_draw()
 
 
 class GstPlayer(GObject.GObject):
-- 
1.7.11.7



More information about the Sugar-devel mailing list