[Sugar-devel] [PATCH] Start filtered activity with keyboard

godiard at sugarlabs.org godiard at sugarlabs.org
Mon Nov 7 07:06:45 EST 2011


From: Gonzalo Odiard <godiard at gmail.com>

This patch complement the filter functionality in the home view.
If only one activity is selected, Return key start the activity.

Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
---
 src/jarabe/desktop/favoritesview.py |    7 +++++++
 src/jarabe/desktop/homewindow.py    |    2 ++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index 132d14f..db3aa36 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -94,6 +94,7 @@ class FavoritesView(hippo.Canvas):
         self._layout = None
         self._alert = None
         self._resume_mode = True
+        self._filtered_icons = []
 
         # More DND stuff
         self.add_events(gtk.gdk.BUTTON_PRESS_MASK |
@@ -113,14 +114,20 @@ class FavoritesView(hippo.Canvas):
 
     def set_filter(self, query):
         query = query.strip()
+        self._filtered_icons = []
         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
+                    self._filtered_icons.append(icon)
                 else:
                     icon.alpha = 0.33
 
+    def start_selected_activity(self):
+        if len(self._filtered_icons) == 1:
+            self._filtered_icons[0]._activate()
+
     def __settings_changed_cb(self, **kwargs):
         favorites_settings = get_settings()
         self._set_layout(favorites_settings.layout)
diff --git a/src/jarabe/desktop/homewindow.py b/src/jarabe/desktop/homewindow.py
index 07deff7..f03b067 100644
--- a/src/jarabe/desktop/homewindow.py
+++ b/src/jarabe/desktop/homewindow.py
@@ -117,6 +117,8 @@ class HomeWindow(gtk.Window):
     def __key_press_event_cb(self, window, event):
         if event.keyval in [gtk.keysyms.Alt_L, gtk.keysyms.Alt_R]:
             self._home_box.set_resume_mode(False)
+        if event.keyval == gtk.keysyms.Return:
+            self._home_box._favorites_view.start_selected_activity()
         return False
 
     def __key_release_event_cb(self, window, event):
-- 
1.7.7



More information about the Sugar-devel mailing list