This patch adds visual indication when the Journal is empty, or when
there are no entries which match the supplied search/filter.  The
design for these indications calls for buttons (which "Return to Home"
or "Clear search", respectively), but this simpler patch is a good
step in the right direction, eliminating the perception that something
is broken due to the otherwise near-empty white screen. (Tickets #3091
and #3772)

- Eben
From ba6f433a12e48c5f283a6700b19f5d76cd4c7dcc Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED](none)>
Date: Mon, 16 Jun 2008 16:06:34 -0400
Subject: [PATCH] Add indications for empty journal and empty search results

---
 listview.py |   61 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 47 insertions(+), 14 deletions(-)

diff --git a/listview.py b/listview.py
index 3d14d49..54782e2 100644
--- a/listview.py
+++ b/listview.py
@@ -14,6 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
+from gettext import gettext as _
 import logging
 import traceback
 import sys
@@ -24,6 +25,7 @@ import gtk
 import dbus
 
 from sugar.graphics import style
+from sugar.graphics.icon import CanvasIcon
 
 from collapsedentry import CollapsedEntry
 import query
@@ -53,11 +55,11 @@ class BaseListView(gtk.HBox):
                         orientation=hippo.ORIENTATION_VERTICAL,
                         background_color=style.COLOR_WHITE.get_int())
 
-        canvas = hippo.Canvas()
-        canvas.set_root(self._box)
+        self._canvas = hippo.Canvas()
+        self._canvas.set_root(self._box)
 
-        self.pack_start(canvas)
-        canvas.show()
+        self.pack_start(self._canvas)
+        self._canvas.show()
 
         self._vadjustment = gtk.Adjustment(value=0, lower=0, upper=0, 
                                            step_incr=1, page_incr=0, page_size=0)
@@ -76,15 +78,32 @@ class BaseListView(gtk.HBox):
         self._press_start_x = None
         self._press_start_y = None
         self._last_clicked_entry = None
-        canvas.drag_source_set(0, [], 0)
-        canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK |
-                          gtk.gdk.POINTER_MOTION_HINT_MASK)
-        canvas.connect_after("motion_notify_event",
-                       self._canvas_motion_notify_event_cb)
-        canvas.connect("button_press_event",
-                       self._canvas_button_press_event_cb)
-        canvas.connect("drag_end", self._drag_end_cb)
-        canvas.connect("drag_data_get", self._drag_data_get_cb)
+        self._canvas.drag_source_set(0, [], 0)
+        self._canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK |
+                                gtk.gdk.POINTER_MOTION_HINT_MASK)
+        self._canvas.connect_after("motion_notify_event",
+                                   self._canvas_motion_notify_event_cb)
+        self._canvas.connect("button_press_event",
+                             self._canvas_button_press_event_cb)
+        self._canvas.connect("drag_end", self._drag_end_cb)
+        self._canvas.connect("drag_data_get", self._drag_data_get_cb)
+
+        # Empty view stuff
+        self._empty_box = hippo.CanvasBox(
+                        orientation=hippo.ORIENTATION_VERTICAL,
+                        background_color=style.COLOR_WHITE.get_int(),
+                        yalign=hippo.ALIGNMENT_CENTER)
+        icon = CanvasIcon(size=style.LARGE_ICON_SIZE,
+                          file_name='activity/activity-journal.svg',
+                          stroke_color = style.COLOR_BUTTON_GREY.get_svg(),
+                          fill_color = style.COLOR_TRANSPARENT.get_svg())
+        self._empty_text = hippo.CanvasText(text=_('No matching entries'),
+                xalign=hippo.ALIGNMENT_CENTER,
+                font_desc=style.FONT_NORMAL.get_pango_desc())
+        self._empty_text.props.color = style.COLOR_BUTTON_GREY.get_int()
+
+        self._empty_box.append(icon)
+        self._empty_box.append(self._empty_text)
 
         # Auto-update stuff
         self._fully_obscured = True
@@ -151,6 +170,12 @@ class BaseListView(gtk.HBox):
 
     def _refresh_view(self, jobjects):
         logging.debug('ListView %r' % self)
+        # Indicate when the Journal is empty
+        if len(jobjects) == 0:
+            self._empty_text.props.text = _('Your Journal is empty')
+            self._canvas.set_root(self._empty_box)
+            return
+
         # Refresh view and create the entries if they don't exist yet.
         for i in range(0, self._page_size):
             try:
@@ -191,7 +216,15 @@ class BaseListView(gtk.HBox):
 
         self._vadjustment.props.value = min(self._vadjustment.props.value,
                                             self._result_set.length - self._page_size)
-        self._do_scroll(force=True)
+        if self._result_set.length == 0:
+            if self._query.has_key('query'):
+                self._empty_text.props.text = _('No matching entries')
+            else:
+                self._empty_text.props.text = _('Your Journal is empty')
+            self._canvas.set_root(self._empty_box)
+        else:
+            self._canvas.set_root(self._box)
+            self._do_scroll(force=True)
 
     def _scroll_event_cb(self, hbox, event):
         if event.direction == gtk.gdk.SCROLL_UP:
-- 
1.5.4.3

_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar

Reply via email to