[Sugar-devel] [PATCH] Implement filter in favorites view - v3

godiard at sugarlabs.org godiard at sugarlabs.org
Thu Aug 18 22:33:59 EDT 2011


From: Gonzalo Odiard <godiard at gmail.com>

After evaluation with Design Team, the filter higlight selected
activities applying a alpha of 0.33 in the unselected activities.
This patch add strip() to the query to avoid accidental filtering
of all activities by adding spaces.

Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
---
 src/jarabe/desktop/favoritesview.py |   10 ++++++++++
 src/jarabe/desktop/homebox.py       |   22 +++++++++-------------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index b609b1b..1be7d76 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -110,6 +110,16 @@ class FavoritesView(hippo.Canvas):
         favorites_settings.changed.connect(self.__settings_changed_cb)
         self._set_layout(favorites_settings.layout)
 
+    def set_filter(self, query):
+        query = query.strip()
+        for icon in self._box.get_children():
+            if icon not in [self._my_icon, self._current_activity]:
+                activity_name = icon._activity_info.get_name().lower()
+                if activity_name.find(query) > -1:
+                    icon.alpha = 1.0
+                else:
+                    icon.alpha = 0.33
+
     def __settings_changed_cb(self, **kwargs):
         favorites_settings = get_settings()
         self._set_layout(favorites_settings.layout)
diff --git a/src/jarabe/desktop/homebox.py b/src/jarabe/desktop/homebox.py
index 661326e..2ee6ae7 100644
--- a/src/jarabe/desktop/homebox.py
+++ b/src/jarabe/desktop/homebox.py
@@ -55,6 +55,7 @@ class HomeBox(gtk.VBox):
         self._toolbar.show()
 
         self._set_view(_FAVORITES_VIEW)
+        self._query = ''
 
     def show_software_updates_alert(self):
         alert = Alert()
@@ -103,8 +104,9 @@ class HomeBox(gtk.VBox):
             panel.set_section_view_auto_close()
 
     def __toolbar_query_changed_cb(self, toolbar, query):
-        query = query.lower()
-        self._list_view.set_filter(query)
+        self._query = query.lower()
+        self._list_view.set_filter(self._query)
+        self._favorites_view.set_filter(self._query)
 
     def __toolbar_view_changed_cb(self, toolbar, view):
         self._set_view(view)
@@ -145,6 +147,9 @@ class HomeBox(gtk.VBox):
 
     def set_resume_mode(self, resume_mode):
         self._favorites_view.set_resume_mode(resume_mode)
+        if resume_mode and self._query != '':
+            self._list_view.set_filter(self._query)
+            self._favorites_view.set_filter(self._query)
 
 
 class HomeToolbar(gtk.Toolbar):
@@ -177,7 +182,6 @@ class HomeToolbar(gtk.Toolbar):
         self.search_entry.connect('activate', self.__entry_activated_cb)
         self.search_entry.connect('changed', self.__entry_changed_cb)
         tool_item.add(self.search_entry)
-        self.search_entry.set_sensitive(False)
         self.search_entry.show()
 
         self._add_separator(expand=True)
@@ -201,14 +205,8 @@ class HomeToolbar(gtk.Toolbar):
 
     def __view_button_toggled_cb(self, button, view):
         if button.props.active:
-            if view == _FAVORITES_VIEW:
-                self.search_entry.set_text('')
-                self.search_entry.set_sensitive(False)
-                self.emit('view-changed', view)
-            else:
-                self.search_entry.set_sensitive(True)
-                self.search_entry.grab_focus()
-                self.emit('view-changed', view)
+            self.search_entry.grab_focus()
+            self.emit('view-changed', view)
 
     def _add_separator(self, expand=False):
         separator = gtk.SeparatorToolItem()
@@ -228,8 +226,6 @@ class HomeToolbar(gtk.Toolbar):
         if self._query != new_query:
             self._query = new_query
 
-            if self._query is not '':
-                self._list_button.props.active = True
             self.emit('query-changed', self._query)
 
     def __entry_changed_cb(self, entry):
-- 
1.7.4.4



More information about the Sugar-devel mailing list