A cleaner attempt.  Thanks.

- Eben


On Tue, Jun 17, 2008 at 11:08 AM, Tomeu Vizoso <[EMAIL PROTECTED]> wrote:
> On Tue, Jun 17, 2008 at 4:33 PM, Eben Eliason <[EMAIL PROTECTED]> wrote:
>> On Tue, Jun 17, 2008 at 9:18 AM, Eben Eliason <[EMAIL PROTECTED]> wrote:
>>> On Tue, Jun 17, 2008 at 3:36 AM, Tomeu Vizoso <[EMAIL PROTECTED]> wrote:
>>>> What about creating the empty_box in a method? We don't really need to
>>>> hold a reference to it in ListView, right? You could then pass the
>>>> string as a parameter to that method, thus avoiding multiple repeated
>>>> instances of translatable strings, that is something quite bad.
>>>
>>> We could use a method.  I want to keep the door open to allowing other
>>> changes apart from the string, in the future.  For instance, as the
>>> commit message indicates, the different cases may have buttons with
>>> different icons/actions in the future.  Perhaps I should just make
>>> separate methods for the two states. What do you think?  Perhaps add
>>> another to clear the message and restore the list as well?
>>
>> Oh, as a side note, implementing this as a single method doesn't take
>> care of the repeated translatable strings, as we'd need to pass the
>> translated string from each location we called the method from.  I
>> suppose you could store a reference to the translated strings in init
>> or something, and then pass those, but that doesn't seem like a good
>> solution to me.
>
> Well, being a separate method or class allows you to add a constant
> parameter/property that signals to use one or the other string.
>
> Thanks,
>
> Tomeu
>
From b1201147bb932994077299ab709922fce983d090 Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED](none)>
Date: Tue, 17 Jun 2008 20:43:52 -0400
Subject: [PATCH] Add indications for empty journal and empty search results

---
 listview.py |   59 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/listview.py b/listview.py
index 3d14d49..3955266 100644
--- a/listview.py
+++ b/listview.py
@@ -17,6 +17,7 @@
 import logging
 import traceback
 import sys
+from gettext import gettext as _
 
 import hippo
 import gobject
@@ -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
@@ -34,6 +36,9 @@ DS_DBUS_PATH = '/org/laptop/sugar/DataStore'
 
 UPDATE_INTERVAL = 300000
 
+EMPTY_JOURNAL = _("Your Journal is empty")
+NO_MATCH = _("No matching entries ")
+
 class BaseListView(gtk.HBox):
     __gtype_name__ = 'BaseListView'
 
@@ -53,11 +58,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 +81,15 @@ 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 |
+        self._canvas.drag_source_set(0, [], 0)
+        self._canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK |
                           gtk.gdk.POINTER_MOTION_HINT_MASK)
-        canvas.connect_after("motion_notify_event",
+        self._canvas.connect_after("motion_notify_event",
                        self._canvas_motion_notify_event_cb)
-        canvas.connect("button_press_event",
+        self._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.connect("drag_end", self._drag_end_cb)
+        self._canvas.connect("drag_data_get", self._drag_data_get_cb)
 
         # Auto-update stuff
         self._fully_obscured = True
@@ -151,6 +156,11 @@ 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._show_message(EMPTY_JOURNAL)
+            return
+
         # Refresh view and create the entries if they don't exist yet.
         for i in range(0, self._page_size):
             try:
@@ -191,7 +201,14 @@ 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._show_message(NO_MATCH)
+            else:
+                self._show_message(EMPTY_JOURNAL)
+        else:
+            self._clear_message()
+            self._do_scroll(force=True)
 
     def _scroll_event_cb(self, hbox, event):
         if event.direction == gtk.gdk.SCROLL_UP:
@@ -273,6 +290,26 @@ class BaseListView(gtk.HBox):
 
         self._reflow_sid = 0
 
+    def _show_message(self, message):
+        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())
+        text = hippo.CanvasText(text=message,
+                xalign=hippo.ALIGNMENT_CENTER,
+                font_desc=style.FONT_NORMAL.get_pango_desc(),
+                color = style.COLOR_BUTTON_GREY.get_int())
+
+        box.append(icon)
+        box.append(text)
+        self._canvas.set_root(box)
+
+    def _clear_message(self):
+        self._canvas.set_root(self._box)
+
     # TODO: Dnd methods. This should be merged somehow inside hippo-canvas.
     def _canvas_motion_notify_event_cb(self, widget, event):
         if not self._pressed_button:
-- 
1.5.4.3

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

Reply via email to