[Sugar-devel] [PATCH shell] Views: defocus the search entry by default

Simon Schampijer simon at schampijer.de
Wed Sep 26 03:40:22 EDT 2012


From: Simon Schampijer <simon at laptop.org>

This patch does implement the following behavior:

- the search entry in all the views (Home (Favorites and Activity list),
  Group and Neighborhood) is unfocused by default

- the search entry can be focused by clicking in the entry or by
  starting to type

- the search entry contains a hint when unfocused and no search has been
  entered, the hint is dependent on the View you are in and matches the
  labels in the View Palettes (Frame), the existing translations have
  been reused

- the learner can defocus the entry by clicking outside somewhere in
  the view (toolbar or canvas), if no search has been entered the hint
  will be displayed again if there is a search entered it will remain
  in effect and the entry will only be unfocused, the latter will help
  to hide the OSK and see the matches for a particular search

- clicking on the clear icon in the entry ('x') the entry will be
  unfocused again

Signed-off-by: Simon Schampijer <simon at laptop.org>
---
 src/jarabe/desktop/activitieslist.py |  4 ++++
 src/jarabe/desktop/favoritesview.py  |  4 ++++
 src/jarabe/desktop/groupbox.py       |  6 +++++-
 src/jarabe/desktop/homebox.py        | 15 +++++++++++++++
 src/jarabe/desktop/homewindow.py     | 23 +++++++++++++++++++----
 src/jarabe/desktop/meshbox.py        |  5 +++++
 src/jarabe/desktop/viewcontainer.py  |  1 +
 src/jarabe/desktop/viewtoolbar.py    |  6 +++++-
 8 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
index b830526..1b5ddd7 100644
--- a/src/jarabe/desktop/activitieslist.py
+++ b/src/jarabe/desktop/activitieslist.py
@@ -375,6 +375,10 @@ class ActivitiesList(Gtk.VBox):
         self._alert = None
         self._clear_message_box = None
 
+    def grab_focus(self):
+        # overwrite grab focus in order to grab focus from the parent
+        self._tree_view.grab_focus()
+
     def set_filter(self, query):
         matches = self._tree_view.set_filter(query)
         if matches == 0:
diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index b73d016..26a89e6 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -85,6 +85,10 @@ class FavoritesBox(Gtk.VBox):
     def set_resume_mode(self, resume_mode):
         self._view.set_resume_mode(resume_mode)
 
+    def grab_focus(self):
+        # overwrite grab focus in order to grab focus from the parent
+        self._view.grab_focus()
+
     def add_alert(self, alert):
         if self._alert is not None:
             self.remove_alert()
diff --git a/src/jarabe/desktop/groupbox.py b/src/jarabe/desktop/groupbox.py
index 3d7c0f3..f916f62 100644
--- a/src/jarabe/desktop/groupbox.py
+++ b/src/jarabe/desktop/groupbox.py
@@ -41,7 +41,8 @@ class GroupBox(ViewContainer):
 
         self._query = ''
         toolbar.connect('query-changed', self._toolbar_query_changed_cb)
-
+        toolbar.search_entry.connect('icon-press',
+                                     self.__clear_icon_pressed_cb)
         self._friends = {}
 
         friends_model = friends.get_model()
@@ -72,3 +73,6 @@ class GroupBox(ViewContainer):
         for icon in self.get_children():
             if hasattr(icon, 'set_filter'):
                 icon.set_filter(self._query)
+
+    def __clear_icon_pressed_cb(self, entry, icon_pos, event):
+        self.grab_focus()
diff --git a/src/jarabe/desktop/homebox.py b/src/jarabe/desktop/homebox.py
index 8eda213..ed5144b 100644
--- a/src/jarabe/desktop/homebox.py
+++ b/src/jarabe/desktop/homebox.py
@@ -45,6 +45,8 @@ class HomeBox(Gtk.VBox):
 
         toolbar.connect('query-changed', self.__toolbar_query_changed_cb)
         toolbar.connect('view-changed', self.__toolbar_view_changed_cb)
+        toolbar.search_entry.connect('icon-press',
+                                     self.__clear_icon_pressed_cb)
         self._list_view.connect('clear-clicked',
                                 self.__activitylist_clear_clicked_cb, toolbar)
 
@@ -108,6 +110,17 @@ class HomeBox(Gtk.VBox):
     def __activitylist_clear_clicked_cb(self, widget, toolbar):
         toolbar.clear_query()
 
+    def __clear_icon_pressed_cb(self, entry, icon_pos, event):
+        self.grab_focus()
+
+    def grab_focus(self):
+        # overwrite grab focus to be able to grab focus on the
+        # views which are packed inside a box
+        if self._list_view in self.get_children():
+            self._list_view.grab_focus()
+        else:
+            self._favorites_box.grab_focus()
+
     def _set_view(self, view):
         if view == _FAVORITES_VIEW:
             if self._list_view in self.get_children():
@@ -116,6 +129,7 @@ class HomeBox(Gtk.VBox):
             if self._favorites_box not in self.get_children():
                 self.add(self._favorites_box)
                 self._favorites_box.show()
+                self._favorites_box.grab_focus()
         elif view == _LIST_VIEW:
             if self._favorites_box in self.get_children():
                 self.remove(self._favorites_box)
@@ -123,6 +137,7 @@ class HomeBox(Gtk.VBox):
             if self._list_view not in self.get_children():
                 self.add(self._list_view)
                 self._list_view.show()
+                self._list_view.grab_focus()
         else:
             raise ValueError('Invalid view: %r' % view)
 
diff --git a/src/jarabe/desktop/homewindow.py b/src/jarabe/desktop/homewindow.py
index 27c81e8..a412b99 100644
--- a/src/jarabe/desktop/homewindow.py
+++ b/src/jarabe/desktop/homewindow.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
 
 from gi.repository import GObject
@@ -64,12 +65,14 @@ class HomeWindow(Gtk.Window):
         self.modify_bg(Gtk.StateType.NORMAL,
                        style.COLOR_WHITE.get_gdk_color())
 
-        self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK)
+        self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK|
+                        Gdk.EventMask.BUTTON_PRESS_MASK)
         self.connect('visibility-notify-event',
                      self._visibility_notify_event_cb)
         self.connect('map-event', self.__map_event_cb)
         self.connect('key-press-event', self.__key_press_event_cb)
         self.connect('key-release-event', self.__key_release_event_cb)
+        self.connect('button-press-event', self.__button_pressed_cb)
 
         self._box = Gtk.VBox()
 
@@ -80,6 +83,7 @@ class HomeWindow(Gtk.Window):
         self._home_box = HomeBox(self._toolbar)
         self._box.pack_start(self._home_box, True, True, 0)
         self._home_box.show()
+        self._home_box.grab_focus()
         self._toolbar.show_view_buttons()
 
         self._group_box = GroupBox(self._toolbar)
@@ -131,6 +135,9 @@ class HomeWindow(Gtk.Window):
             self._activate_view(shell.get_model().zoom_level)
 
     def __key_press_event_cb(self, window, event):
+        if not self._toolbar.search_entry.has_focus():
+            self._toolbar.search_entry.grab_focus()
+
         if event.keyval in [Gdk.KEY_Alt_L, Gdk.KEY_Alt_R]:
             self._home_box.set_resume_mode(False)
         return False
@@ -140,6 +147,11 @@ class HomeWindow(Gtk.Window):
             self._home_box.set_resume_mode(True)
         return False
 
+    def __button_pressed_cb(self, widget, event):
+        current_box = self._box.get_children()[1]
+        current_box.grab_focus()
+        return False
+
     def __map_event_cb(self, window, event):
         # have to make the desktop window active
         # since metacity doesn't make it on startup
@@ -197,19 +209,22 @@ class HomeWindow(Gtk.Window):
             self._box.pack_start(self._home_box, True, True, 0)
             self._home_box.show()
             self._toolbar.clear_query()
-            self._toolbar.search_entry.grab_focus()
+            self._toolbar.set_placeholder_text_for_view(_('Home'))
+            self._home_box.grab_focus()
             self._toolbar.show_view_buttons()
         elif level == ShellModel.ZOOM_GROUP:
             self._box.pack_start(self._group_box, True, True, 0)
             self._group_box.show()
             self._toolbar.clear_query()
-            self._toolbar.search_entry.grab_focus()
+            self._toolbar.set_placeholder_text_for_view(_('Group'))
+            self._group_box.grab_focus()
             self._toolbar.hide_view_buttons()
         elif level == ShellModel.ZOOM_MESH:
             self._box.pack_start(self._mesh_box, True, True, 0)
             self._mesh_box.show()
             self._toolbar.clear_query()
-            self._toolbar.search_entry.grab_focus()
+            self._toolbar.set_placeholder_text_for_view(_('Neighborhood'))
+            self._mesh_box.grab_focus()
             self._toolbar.hide_view_buttons()
 
     def get_home_box(self):
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index 049263e..e1c8381 100644
--- a/src/jarabe/desktop/meshbox.py
+++ b/src/jarabe/desktop/meshbox.py
@@ -362,6 +362,8 @@ class MeshBox(ViewContainer):
         self._query = ''
 
         toolbar.connect('query-changed', self._toolbar_query_changed_cb)
+        toolbar.search_entry.connect('icon-press',
+                                     self.__clear_icon_pressed_cb)
 
         for buddy_model in self._model.get_buddies():
             self._add_buddy(buddy_model)
@@ -590,3 +592,6 @@ class MeshBox(ViewContainer):
         for icon in self.get_children():
             if hasattr(icon, 'set_filter'):
                 icon.set_filter(self._query)
+
+    def __clear_icon_pressed_cb(self, entry, icon_pos, event):
+        self.grab_focus()
diff --git a/src/jarabe/desktop/viewcontainer.py b/src/jarabe/desktop/viewcontainer.py
index 1675293..76f5a69 100644
--- a/src/jarabe/desktop/viewcontainer.py
+++ b/src/jarabe/desktop/viewcontainer.py
@@ -26,6 +26,7 @@ class ViewContainer(Gtk.Container):
     def __init__(self, layout, owner_icon, activity_icon=None, **kwargs):
         Gtk.Container.__init__(self, **kwargs)
         self.set_has_window(False)
+        self.set_can_focus(True)
 
         self._activity_icon = None
         self._owner_icon = None
diff --git a/src/jarabe/desktop/viewtoolbar.py b/src/jarabe/desktop/viewtoolbar.py
index 09b4512..5cb0186 100644
--- a/src/jarabe/desktop/viewtoolbar.py
+++ b/src/jarabe/desktop/viewtoolbar.py
@@ -59,6 +59,7 @@ class ViewToolbar(Gtk.Toolbar):
         self.search_entry = iconentry.IconEntry()
         self.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
                                              'system-search')
+        self.set_placeholder_text_for_view(_('Home'))
         self.search_entry.add_clear_button()
         self.search_entry.set_width_chars(25)
         self.search_entry.connect('activate', self._entry_activated_cb)
@@ -95,6 +96,10 @@ class ViewToolbar(Gtk.Toolbar):
     def clear_query(self):
         self.search_entry.props.text = ''
 
+    def set_placeholder_text_for_view(self, view_name):
+        text = _('Search in %s') % view_name
+        self.search_entry.set_placeholder_text(text)
+
     def _add_separator(self, expand=False):
         separator = Gtk.SeparatorToolItem()
         separator.props.draw = False
@@ -132,7 +137,6 @@ class ViewToolbar(Gtk.Toolbar):
 
     def __view_button_toggled_cb(self, button, view):
         if button.props.active:
-            self.search_entry.grab_focus()
             self.emit('view-changed', view)
 
 
-- 
1.7.11.4



More information about the Sugar-devel mailing list