[Sugar-devel] [PATCH sugar] Implement filter in the favorites view

godiard at sugarlabs.org godiard at sugarlabs.org
Mon Aug 15 00:14:58 EDT 2011


From: Gonzalo Odiard <godiard at gmail.com>

The patch change the alpha value of the activities icons
acording to the filter to highlight the requested activities.

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

diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index b609b1b..beb123e 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):
+        logging.debug("set filter query:%s", query)
+        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.2
+
     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..c7e88ad 100644
--- a/src/jarabe/desktop/homebox.py
+++ b/src/jarabe/desktop/homebox.py
@@ -105,6 +105,7 @@ class HomeBox(gtk.VBox):
     def __toolbar_query_changed_cb(self, toolbar, query):
         query = query.lower()
         self._list_view.set_filter(query)
+        self._favorites_view.set_filter(query)
 
     def __toolbar_view_changed_cb(self, toolbar, view):
         self._set_view(view)
@@ -177,7 +178,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 +201,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 +222,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