Ticket #4158: 0001-Show-No-media-message-when-Jukebox-starts-from-scrat.patch

File 0001-Show-No-media-message-when-Jukebox-starts-from-scrat.patch, 7.7 KB (added by humitos, 11 years ago)
  • new file emptypanel.py

    From b16d887468877d6b72b2bbddc68610e2ee416147 Mon Sep 17 00:00:00 2001
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Mon, 5 Nov 2012 12:40:23 -0300
    Subject: [PATCH Jukebox] Show 'No media' message when Jukebox starts from
     scratch
    
    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@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
    - +  
     1import logging
     2
     3from gi.repository import Gtk
     4
     5from sugar3.graphics import style
     6from sugar3.graphics.icon import Icon
     7
     8
     9def show(activity, icon_name, message, btn_label, btn_callback):
     10    empty_widgets = Gtk.EventBox()
     11    empty_widgets.modify_bg(Gtk.StateType.NORMAL,
     12                            style.COLOR_WHITE.get_gdk_color())
     13
     14    vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
     15    mvbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
     16    vbox.pack_start(mvbox, True, False, 0)
     17
     18    image_icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
     19                      icon_name=icon_name,
     20                      stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
     21                      fill_color=style.COLOR_TRANSPARENT.get_svg())
     22    mvbox.pack_start(image_icon, False, False, style.DEFAULT_PADDING)
     23
     24    label = Gtk.Label('<span foreground="%s"><b>%s</b></span>' %
     25                      (style.COLOR_BUTTON_GREY.get_html(),
     26                       message))
     27    label.set_use_markup(True)
     28    mvbox.pack_start(label, False, False, style.DEFAULT_PADDING)
     29
     30    hbox = Gtk.Box()
     31    open_image_btn = Gtk.Button()
     32    open_image_btn.connect('clicked', btn_callback)
     33    add_image = Gtk.Image.new_from_stock(Gtk.STOCK_ADD,
     34                                         Gtk.IconSize.BUTTON)
     35    buttonbox = Gtk.Box()
     36    buttonbox.pack_start(add_image, False, True, 0)
     37    buttonbox.pack_end(Gtk.Label(btn_label), True, True, 5)
     38    open_image_btn.add(buttonbox)
     39    hbox.pack_start(open_image_btn, True, False, 0)
     40    mvbox.pack_start(hbox, False, False, style.DEFAULT_PADDING)
     41
     42    empty_widgets.add(vbox)
     43    empty_widgets.show_all()
     44    logging.error('Showing empty Panel')
     45    activity.set_canvas(empty_widgets)
  • new file icons/activity-jukebox.svg

    diff --git a/icons/activity-jukebox.svg b/icons/activity-jukebox.svg
    new file mode 100644
    index 0000000..b921d4f
    - +  
     1<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 1.1//EN'  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
     2        <!ENTITY stroke_color "#010101">
     3        <!ENTITY fill_color "#FFFFFF">
     4]><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">
     5        <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"/>
     6</g></svg>
     7
  • jukeboxactivity.py

    diff --git a/jukeboxactivity.py b/jukeboxactivity.py
    index 1bc4d4a..bde15a3 100644
    a b  
    2424import sys
    2525import logging
    2626import tempfile
     27import emptypanel
    2728from gettext import gettext as _
    2829import os
    2930
    class JukeboxActivity(activity.Activity): 
    152153        # self.bin = Gtk.HBox()
    153154        # self.bin.show()
    154155
    155         self.canvas = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
     156        self._video_canvas = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    156157        self._alert = None
    157158
    158159        self.playlist_widget = PlayListWidget(self.play)
    159160        self.playlist_widget.update(self.playlist)
    160161        self.playlist_widget.show()
    161         self.canvas.pack_start(self.playlist_widget, False, True, 0)
     162        self._video_canvas.pack_start(self.playlist_widget, False, True, 0)
    162163        self._empty_widget = Gtk.Label(label="")
    163164        self._empty_widget.show()
    164165        self.videowidget = VideoWidget()
    165         self.set_canvas(self.canvas)
     166        self.set_canvas(self._video_canvas)
    166167        self._init_view_area()
    167168        self.show_all()
    168         self.canvas.connect('size-allocate', self.__size_allocate_cb)
     169        self._video_canvas.connect('size-allocate', self.__size_allocate_cb)
    169170
    170         #From ImageViewer Activity
    171171        self._want_document = True
    172172        if self._object_id is None:
    173             self._show_object_picker = GObject.timeout_add(1000, \
    174             self._show_picker_cb)
     173            emptypanel.show(self, 'activity-jukebox',
     174                            _('No media'), _('Choose media files'),
     175                            self._show_picker_cb)
     176        else:
     177            self._init_gstplayer()
    175178
    176179        if handle.uri:
    177180            self.uri = handle.uri
    178181            GObject.idle_add(self._start, self.uri, handle.title)
    179182
     183    def _init_gstplayer(self):
    180184        # Create the player just once
    181185        logging.debug('Instantiating GstPlayer')
    182186        self.player = GstPlayer(self.videowidget)
    class JukeboxActivity(activity.Activity): 
    205209        self.view_area.set_show_tabs(False)
    206210        self.view_area.append_page(self._empty_widget, None)
    207211        self.view_area.append_page(self.videowidget, None)
    208         self.canvas.pack_end(self.view_area, expand=True,
     212        self._video_canvas.pack_end(self.view_area, expand=True,
    209213                             fill=True, padding=0)
    210214
    211215    def _switch_canvas(self, show_video):
    class JukeboxActivity(activity.Activity): 
    219223            self.view_area.set_current_page(1)
    220224        else:
    221225            self.view_area.set_current_page(0)
    222         self.canvas.queue_draw()
     226        self._video_canvas.queue_draw()
    223227
    224228    def __size_allocate_cb(self, widget, allocation):
    225         canvas_size = self.canvas.get_allocation()
     229        canvas_size = self._video_canvas.get_allocation()
    226230        playlist_width = int(canvas_size.width * PLAYLIST_WIDTH_PROP)
    227231        self.playlist_widget.set_size_request(playlist_width, 0)
    228232
    class JukeboxActivity(activity.Activity): 
    380384        logging.debug("shared start")
    381385        pass
    382386
    383     def _show_picker_cb(self):
     387    def _show_picker_cb(self, button=None):
    384388        #From ImageViewer Activity
    385389        if not self._want_document:
    386390            return
    class JukeboxActivity(activity.Activity): 
    403407                    title = jobject.metadata.get('title', None)
    404408                    self._load_file(jobject.file_path, title,
    405409                            jobject.object_id)
     410
     411                    if button is not None:
     412                        # called from the "Choose media files" button
     413                        # from EmptyPanel
     414                        self.set_canvas(self._video_canvas)
     415                        self._init_gstplayer()
     416
    406417        finally:
    407418            #chooser.destroy()
    408419            #del chooser
    class JukeboxActivity(activity.Activity): 
    654665            self.playlist_widget.hide()
    655666        else:
    656667            self.playlist_widget.show_all()
    657         self.canvas.queue_draw()
     668        self._video_canvas.queue_draw()
    658669
    659670
    660671class GstPlayer(GObject.GObject):