Ticket #4159: 0001-Show-No-book-message-when-Read-starts-from-scratch.patch

File 0001-Show-No-book-message-when-Read-starts-from-scratch.patch, 5.7 KB (added by humitos, 11 years ago)
  • new file emptypanel.py

    From 2c58bf5a0318edc140950f072b50dab82c6a9420 Mon Sep 17 00:00:00 2001
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Mon, 5 Nov 2012 11:48:27 -0300
    Subject: [PATCH Read] Show 'No book' message when Read starts from scratch
    
    When the user starts a new instance of Read the 'No book' message is
    shown with a button to 'Choose a book' that opens the Object Chooser.
    
    Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
    ---
     emptypanel.py           | 45 +++++++++++++++++++++++++++++++++++++++++++++
     icons/activity-read.svg | 11 +++++++++++
     readactivity.py         |  8 ++++++--
     3 files changed, 62 insertions(+), 2 deletions(-)
     create mode 100644 emptypanel.py
     create mode 100644 icons/activity-read.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-read.svg

    diff --git a/icons/activity-read.svg b/icons/activity-read.svg
    new file mode 100644
    index 0000000..d0d1804
    - +  
     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-read">
     5        <path d="M27.904,11.023h-0.002   c0-0.002-1.71-2.053-9.376-2.504C10.86,8.07,6.843,10.121,6.84,10.122c-1.898,0.619-3.495,1.735-3.495,3.494v27.702   c0,2.025,1.235,3.494,3.495,3.494c0.003,0,4.41-1.35,10.004-1.35c5.589-0.001,11.061,2.253,11.061,2.253" display="inline" fill="&fill_color;" stroke="&stroke_color;" stroke-linejoin="round" stroke-width="3.5"/>
     6        <path d="M27.898,11.023   L27.898,11.023c0-0.002,1.715-2.053,9.377-2.504c7.668-0.449,11.686,1.602,11.688,1.603c1.897,0.619,3.494,1.735,3.494,3.494   v27.702c0,2.025-1.233,3.494-3.494,3.494c-0.003,0-4.409-1.35-10.004-1.35c-5.589-0.001-11.062,2.253-11.062,2.253" display="inline" fill="&fill_color;" stroke="&stroke_color;" stroke-linejoin="round" stroke-width="3.5"/>
     7
     8                <line display="inline" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5" x1="27.898" x2="27.9" y1="11.023" y2="45.717"/>
     9        <path d="   M32.566,44.275c0,0-0.031,2.906-4.666,2.906c-4.632,0-4.663-2.906-4.663-2.906" display="inline" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5"/>
     10</g></svg>
     11
  • readactivity.py

    diff --git a/readactivity.py b/readactivity.py
    index 17f8455..846fef9 100644
    a b import re 
    2525import md5
    2626import StringIO
    2727import cairo
     28import emptypanel
    2829
    2930import dbus
    3031from gi.repository import GObject
    class ReadActivity(activity.Activity): 
    335336                self.connect("joined", self._joined_cb)
    336337        elif self._object_id is None:
    337338            # Not joining, not resuming
    338             self._show_journal_object_picker()
     339            emptypanel.show(self, 'activity-read',
     340                            _('No book'), _('Choose a book'),
     341                            self._show_journal_object_picker_cb)
    339342
    340343    def _create_back_button(self):
    341344        back = ToolButton('go-previous-paired')
    class ReadActivity(activity.Activity): 
    612615        else:
    613616            logging.debug('link "%s" not found in the toc model', current_link)
    614617
    615     def _show_journal_object_picker(self):
     618    def _show_journal_object_picker_cb(self, button):
    616619        """Show the journal object picker to load a document.
    617620
    618621        This is for if Read is launched without a document.
    class ReadActivity(activity.Activity): 
    628631                jobject = chooser.get_selected_object()
    629632                if jobject and jobject.file_path:
    630633                    self.read_file(jobject.file_path)
     634                    self.set_canvas(self._vbox)
    631635        finally:
    632636            chooser.destroy()
    633637            del chooser