[Sugar-devel] [PATCH sugar] Group View: add search toolbar

Manuel Quiñones manuq at laptop.org
Mon Aug 27 08:01:03 EDT 2012


Great Simon,

the only thing I see is that we should focus the search entry, like in
the other views:

--- a/src/jarabe/desktop/homewindow.py
+++ b/src/jarabe/desktop/homewindow.py
@@ -182,6 +182,7 @@ class HomeWindow(gtk.Window):
         elif level == ShellModel.ZOOM_GROUP:
             self.add(self._group_box)
             self._group_box.show()
+            self._group_box.focus_search_entry()
         elif level == ShellModel.ZOOM_MESH:
             self.add(self._mesh_box)
             self._mesh_box.show()


2012/8/27 Simon Schampijer <simon at schampijer.de>:
> From: Simon Schampijer <simon at laptop.org>
>
> This adds a search toolbar to the Group View. The toolbar in the
> Neighborhood View has been outsourced to be usable in both Views.
>
> Signed-off-by: Simon Schampijer <simon at laptop.org>

Acked-by: Manuel Quiñones <manuq at laptop.org>

> ---
>  src/jarabe/desktop/Makefile.am    |  3 +-
>  src/jarabe/desktop/groupbox.py    | 41 +++++++++++++----
>  src/jarabe/desktop/meshbox.py     | 77 +------------------------------
>  src/jarabe/desktop/viewtoolbar.py | 97 +++++++++++++++++++++++++++++++++++++++
>  4 files changed, 132 insertions(+), 86 deletions(-)
>  create mode 100644 src/jarabe/desktop/viewtoolbar.py
>
> diff --git a/src/jarabe/desktop/Makefile.am b/src/jarabe/desktop/Makefile.am
> index b36404e..e27bc9c 100644
> --- a/src/jarabe/desktop/Makefile.am
> +++ b/src/jarabe/desktop/Makefile.am
> @@ -15,4 +15,5 @@ sugar_PYTHON =                        \
>          schoolserver.py                \
>         snowflakelayout.py      \
>         transitionbox.py        \
> -       viewcontainer.py
> +       viewcontainer.py        \
> +       viewtoolbar.py
> diff --git a/src/jarabe/desktop/groupbox.py b/src/jarabe/desktop/groupbox.py
> index 8beec90..94a5c10 100644
> --- a/src/jarabe/desktop/groupbox.py
> +++ b/src/jarabe/desktop/groupbox.py
> @@ -16,27 +16,23 @@
>
>  import logging
>
> -import gconf
> +import gtk
>
>  from sugar.graphics import style
> -from sugar.graphics.xocolor import XoColor
>
>  from jarabe.view.buddyicon import BuddyIcon
> -from jarabe.view.buddymenu import BuddyMenu
> -from jarabe.view.eventicon import EventIcon
>  from jarabe.model.buddy import get_owner_instance
>  from jarabe.model import friends
>  from jarabe.desktop.friendview import FriendView
>  from jarabe.desktop.viewcontainer import ViewContainer
>  from jarabe.desktop.favoriteslayout import SpreadLayout
> +from jarabe.desktop.viewtoolbar import ViewToolbar
>
>
> -class GroupBox(ViewContainer):
> -    __gtype_name__ = 'SugarGroupBox'
> +class GroupContainer(ViewContainer):
> +    __gtype_name__ = 'SugarGroupContainer'
>
>      def __init__(self):
> -        logging.debug('STARTUP: Loading the group view')
> -
>          layout = SpreadLayout()
>
>          # Round off icon size to an even number to ensure that the icon
> @@ -44,6 +40,25 @@ class GroupBox(ViewContainer):
>                                 style.LARGE_ICON_SIZE & ~1)
>          ViewContainer.__init__(self, layout, owner_icon)
>
> +
> +class GroupBox(gtk.VBox):
> +    __gtype_name__ = 'SugarGroupBox'
> +
> +    def __init__(self):
> +        logging.debug('STARTUP: Loading the group view')
> +
> +        gtk.VBox.__init__(self)
> +
> +        self._query = ''
> +        self._toolbar = ViewToolbar()
> +        self._toolbar.connect('query-changed', self._toolbar_query_changed_cb)
> +        self.pack_start(self._toolbar, expand=False)
> +        self._toolbar.show()
> +
> +        self._group_container = GroupContainer()
> +        self.add(self._group_container)
> +        self._group_container.show()
> +
>          self._friends = {}
>
>          friends_model = friends.get_model()
> @@ -56,7 +71,7 @@ class GroupBox(ViewContainer):
>
>      def add_friend(self, buddy_info):
>          icon = FriendView(buddy_info)
> -        self.add(icon)
> +        self._group_container.add(icon)
>          self._friends[buddy_info.get_key()] = icon
>          icon.show()
>
> @@ -65,6 +80,12 @@ class GroupBox(ViewContainer):
>
>      def _friend_removed_cb(self, data_model, key):
>          icon = self._friends[key]
> -        self.remove(icon)
> +        self._group_container.remove(icon)
>          del self._friends[key]
>          icon.destroy()
> +
> +    def _toolbar_query_changed_cb(self, toolbar, query):
> +        self._query = query.lower()
> +        for icon in self._group_container.get_children():
> +            if hasattr(icon, 'set_filter'):
> +                icon.set_filter(self._query)
> diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
> index 412a093..8002a33 100644
> --- a/src/jarabe/desktop/meshbox.py
> +++ b/src/jarabe/desktop/meshbox.py
> @@ -29,21 +29,19 @@ import gconf
>  from sugar.graphics.icon import Icon
>  from sugar.graphics import style
>  from sugar.graphics import palette
> -from sugar.graphics import iconentry
>  from sugar.graphics.menuitem import MenuItem
> -from sugar.graphics.xocolor import XoColor
>
>  from jarabe.desktop.snowflakelayout import SnowflakeLayout
>  from jarabe.model import neighborhood
>  from jarabe.model.buddy import get_owner_instance
>  from jarabe.view.buddyicon import BuddyIcon
> -from jarabe.view.buddymenu import BuddyMenu
>  from jarabe.view.eventicon import EventIcon
>  from jarabe.desktop.networkviews import WirelessNetworkView
>  from jarabe.desktop.networkviews import OlpcMeshView
>  from jarabe.desktop.networkviews import SugarAdhocView
>  from jarabe.desktop.viewcontainer import ViewContainer
>  from jarabe.desktop.favoriteslayout import SpreadLayout
> +from jarabe.desktop.viewtoolbar import ViewToolbar
>  from jarabe.model import network
>  from jarabe.model.network import AccessPoint
>  from jarabe.model.olpcmesh import OlpcMeshManager
> @@ -54,9 +52,6 @@ from jarabe.journal import misc
>  _AP_ICON_NAME = 'network-wireless'
>  _OLPC_MESH_ICON_NAME = 'network-mesh'
>
> -_AUTOSEARCH_TIMEOUT = 1000
> -_FILTERED_ALPHA = 0.33
> -
>
>  class _ActivityIcon(EventIcon):
>      def __init__(self, model, file_name, xo_color,
> @@ -161,74 +156,6 @@ class ActivityView(SnowflakeLayout):
>                  icon.set_filter(query)
>
>
> -class MeshToolbar(gtk.Toolbar):
> -    __gtype_name__ = 'MeshToolbar'
> -
> -    __gsignals__ = {
> -        'query-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
> -                          ([str])),
> -    }
> -
> -    def __init__(self):
> -        gtk.Toolbar.__init__(self)
> -
> -        self._query = None
> -        self._autosearch_timer = None
> -
> -        self._add_separator()
> -
> -        tool_item = gtk.ToolItem()
> -        self.insert(tool_item, -1)
> -        tool_item.show()
> -
> -        self.search_entry = iconentry.IconEntry()
> -        self.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
> -                                             'system-search')
> -        self.search_entry.add_clear_button()
> -        self.search_entry.set_width_chars(25)
> -        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.show()
> -
> -        self._add_separator(expand=True)
> -
> -    def _add_separator(self, expand=False):
> -        separator = gtk.SeparatorToolItem()
> -        separator.props.draw = False
> -        if expand:
> -            separator.set_expand(True)
> -        else:
> -            separator.set_size_request(style.GRID_CELL_SIZE,
> -                                       style.GRID_CELL_SIZE)
> -        self.insert(separator, -1)
> -        separator.show()
> -
> -    def _entry_activated_cb(self, entry):
> -        if self._autosearch_timer:
> -            gobject.source_remove(self._autosearch_timer)
> -        new_query = entry.props.text
> -        if self._query != new_query:
> -            self._query = new_query
> -            self.emit('query-changed', self._query)
> -
> -    def _entry_changed_cb(self, entry):
> -        if not entry.props.text:
> -            entry.activate()
> -            return
> -
> -        if self._autosearch_timer:
> -            gobject.source_remove(self._autosearch_timer)
> -        self._autosearch_timer = gobject.timeout_add(_AUTOSEARCH_TIMEOUT,
> -                                                     self._autosearch_timer_cb)
> -
> -    def _autosearch_timer_cb(self):
> -        logging.debug('_autosearch_timer_cb')
> -        self._autosearch_timer = None
> -        self.search_entry.activate()
> -        return False
> -
> -
>  class DeviceObserver(gobject.GObject):
>      __gsignals__ = {
>          'access-point-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
> @@ -440,7 +367,7 @@ class MeshBox(gtk.VBox):
>          self._suspended = True
>          self._query = ''
>
> -        self._toolbar = MeshToolbar()
> +        self._toolbar = ViewToolbar()
>          self._toolbar.connect('query-changed', self._toolbar_query_changed_cb)
>          self.pack_start(self._toolbar, expand=False)
>          self._toolbar.show()
> diff --git a/src/jarabe/desktop/viewtoolbar.py b/src/jarabe/desktop/viewtoolbar.py
> new file mode 100644
> index 0000000..9db301a
> --- /dev/null
> +++ b/src/jarabe/desktop/viewtoolbar.py
> @@ -0,0 +1,97 @@
> +# Copyright (C) 2006-2007 Red Hat, Inc.
> +# Copyright (C) 2009 Tomeu Vizoso, Simon Schampijer
> +# Copyright (C) 2009-2012 One Laptop per Child
> +# Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> +
> +import logging
> +
> +import gtk
> +import gobject
> +
> +from sugar.graphics import style
> +from sugar.graphics import iconentry
> +
> +_AUTOSEARCH_TIMEOUT = 1000
> +_FILTERED_ALPHA = 0.33
> +
> +
> +class ViewToolbar(gtk.Toolbar):
> +    __gtype_name__ = 'SugarViewToolbar'
> +
> +    __gsignals__ = {
> +        'query-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
> +                          ([str])),
> +    }
> +
> +    def __init__(self):
> +        gtk.Toolbar.__init__(self)
> +
> +        self._query = None
> +        self._autosearch_timer = None
> +
> +        self._add_separator()
> +
> +        tool_item = gtk.ToolItem()
> +        self.insert(tool_item, -1)
> +        tool_item.show()
> +
> +        self.search_entry = iconentry.IconEntry()
> +        self.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
> +                                             'system-search')
> +        self.search_entry.add_clear_button()
> +        self.search_entry.set_width_chars(25)
> +        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.show()
> +
> +        self._add_separator(expand=True)
> +
> +    def _add_separator(self, expand=False):
> +        separator = gtk.SeparatorToolItem()
> +        separator.props.draw = False
> +        if expand:
> +            separator.set_expand(True)
> +        else:
> +            separator.set_size_request(style.GRID_CELL_SIZE,
> +                                       style.GRID_CELL_SIZE)
> +        self.insert(separator, -1)
> +        separator.show()
> +
> +    def _entry_activated_cb(self, entry):
> +        if self._autosearch_timer:
> +            gobject.source_remove(self._autosearch_timer)
> +        new_query = entry.props.text
> +        if self._query != new_query:
> +            self._query = new_query
> +            self.emit('query-changed', self._query)
> +
> +    def _entry_changed_cb(self, entry):
> +        if not entry.props.text:
> +            entry.activate()
> +            return
> +
> +        if self._autosearch_timer:
> +            gobject.source_remove(self._autosearch_timer)
> +        self._autosearch_timer = gobject.timeout_add(_AUTOSEARCH_TIMEOUT,
> +                                                     self._autosearch_timer_cb)
> +
> +    def _autosearch_timer_cb(self):
> +        logging.debug('_autosearch_timer_cb')
> +        self._autosearch_timer = None
> +        self.search_entry.activate()
> +        return False
> --
> 1.7.11.4
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel



-- 
.. manuq ..


More information about the Sugar-devel mailing list