[Sugar-devel] [PATCH Read] Show 'No book' message when Read starts from scratch

Manuel Kaufmann humitos at gmail.com
Mon Nov 5 09:51:21 EST 2012


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 at 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
--- /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-read.svg b/icons/activity-read.svg
new file mode 100644
index 0000000..d0d1804
--- /dev/null
+++ b/icons/activity-read.svg
@@ -0,0 +1,11 @@
+<?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-read">
+	<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"/>
+	<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"/>
+
+		<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"/>
+	<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"/>
+</g></svg>
+
diff --git a/readactivity.py b/readactivity.py
index 17f8455..846fef9 100644
--- a/readactivity.py
+++ b/readactivity.py
@@ -25,6 +25,7 @@ import re
 import md5
 import StringIO
 import cairo
+import emptypanel
 
 import dbus
 from gi.repository import GObject
@@ -335,7 +336,9 @@ class ReadActivity(activity.Activity):
                 self.connect("joined", self._joined_cb)
         elif self._object_id is None:
             # Not joining, not resuming
-            self._show_journal_object_picker()
+            emptypanel.show(self, 'activity-read',
+                            _('No book'), _('Choose a book'),
+                            self._show_journal_object_picker_cb)
 
     def _create_back_button(self):
         back = ToolButton('go-previous-paired')
@@ -612,7 +615,7 @@ class ReadActivity(activity.Activity):
         else:
             logging.debug('link "%s" not found in the toc model', current_link)
 
-    def _show_journal_object_picker(self):
+    def _show_journal_object_picker_cb(self, button):
         """Show the journal object picker to load a document.
 
         This is for if Read is launched without a document.
@@ -628,6 +631,7 @@ class ReadActivity(activity.Activity):
                 jobject = chooser.get_selected_object()
                 if jobject and jobject.file_path:
                     self.read_file(jobject.file_path)
+                    self.set_canvas(self._vbox)
         finally:
             chooser.destroy()
             del chooser
-- 
1.7.11.7



More information about the Sugar-devel mailing list