[Sugar-devel] [PATCH sugar] Views: move the ViewToolbar to the HomeWindow instead of having one in each View

Manuel Quiñones manuq at laptop.org
Tue Aug 28 08:14:35 EDT 2012


Great work :)

So now the filtering is shared between the three views.  I think this
is worth noting in the commit message.

Please push this and the previous patch (the one that this depends).

2012/8/28 Simon Schampijer <simon at schampijer.de>:
> From: Simon Schampijer <simon at laptop.org>
>
> This patch moves the ViewToolbar to the HomeWindow and removes it
> from the Views respectively. This ease the transition between the
> Views and simplifies the code.
>
> The toolbar is passed as an argument at initialization of the
> View in order to connect to the 'query-changed' and 'view-changed'
> signals of the toolbar. The buttons to change between the Favorite
> and ListView are only available in the HomeView at the moment, they
> are hidden and shown when we switch between the Views.
>
> The _FILTERED_ALPHA global is added back again to the MeshView, it
> has been dropped accidentally by 13844c18b225f46b1636fc1201e020af53c60fcd.
>
> This patch depends on the previous toolbar simplification patch [1].
>
> Signed-off-by: Simon Schampijer <simon at laptop.org>
>
> [1] http://lists.sugarlabs.org/archive/sugar-devel/2012-August/039328.html
> ---
>  src/jarabe/desktop/groupbox.py      |  38 +++----------
>  src/jarabe/desktop/homebox.py       | 110 +-----------------------------------
>  src/jarabe/desktop/homewindow.py    |  47 ++++++++++-----
>  src/jarabe/desktop/meshbox.py       |  56 +++++++-----------
>  src/jarabe/desktop/transitionbox.py |  14 +++--
>  src/jarabe/desktop/viewtoolbar.py   |  89 ++++++++++++++++++++++++++++-
>  6 files changed, 162 insertions(+), 192 deletions(-)
>
> diff --git a/src/jarabe/desktop/groupbox.py b/src/jarabe/desktop/groupbox.py
> index e58ac3f..b86cdf2 100644
> --- a/src/jarabe/desktop/groupbox.py
> +++ b/src/jarabe/desktop/groupbox.py
> @@ -16,8 +16,6 @@
>
>  import logging
>
> -import gtk
> -
>  from sugar.graphics import style
>
>  from jarabe.view.buddyicon import BuddyIcon
> @@ -26,13 +24,14 @@ 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 GroupContainer(ViewContainer):
> -    __gtype_name__ = 'SugarGroupContainer'
> +class GroupBox(ViewContainer):
> +    __gtype_name__ = 'SugarGroupBox'
> +
> +    def __init__(self, toolbar):
> +        logging.debug('STARTUP: Loading the group view')
>
> -    def __init__(self):
>          layout = SpreadLayout()
>
>          # Round off icon size to an even number to ensure that the icon
> @@ -40,24 +39,8 @@ class GroupContainer(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()
> +        toolbar.connect('query-changed', self._toolbar_query_changed_cb)
>
>          self._friends = {}
>
> @@ -71,7 +54,7 @@ class GroupBox(gtk.VBox):
>
>      def add_friend(self, buddy_info):
>          icon = FriendView(buddy_info)
> -        self._group_container.add(icon)
> +        self.add(icon)
>          self._friends[buddy_info.get_key()] = icon
>          icon.show()
>
> @@ -80,15 +63,12 @@ class GroupBox(gtk.VBox):
>
>      def _friend_removed_cb(self, data_model, key):
>          icon = self._friends[key]
> -        self._group_container.remove(icon)
> +        self.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():
> +        for icon in self.get_children():
>              if hasattr(icon, 'set_filter'):
>                  icon.set_filter(self._query)
> -
> -    def focus_search_entry(self):
> -        self._toolbar.search_entry.grab_focus()
> diff --git a/src/jarabe/desktop/homebox.py b/src/jarabe/desktop/homebox.py
> index e4dba30..8f3963b 100644
> --- a/src/jarabe/desktop/homebox.py
> +++ b/src/jarabe/desktop/homebox.py
> @@ -22,13 +22,11 @@ import gobject
>  import gtk
>
>  from sugar.graphics import style
> -from sugar.graphics.radiotoolbutton import RadioToolButton
>  from sugar.graphics.alert import Alert
>  from sugar.graphics.icon import Icon
>
>  from jarabe.desktop import favoritesview
>  from jarabe.desktop.activitieslist import ActivitiesList
> -from jarabe.desktop.viewtoolbar import ViewToolbar
>
>  _FAVORITES_VIEW = 0
>  _LIST_VIEW = 1
> @@ -37,7 +35,7 @@ _LIST_VIEW = 1
>  class HomeBox(gtk.VBox):
>      __gtype_name__ = 'SugarHomeBox'
>
> -    def __init__(self):
> +    def __init__(self, toolbar):
>          logging.debug('STARTUP: Loading the home view')
>
>          gobject.GObject.__init__(self)
> @@ -45,11 +43,8 @@ class HomeBox(gtk.VBox):
>          self._favorites_box = favoritesview.FavoritesBox()
>          self._list_view = ActivitiesList()
>
> -        self._toolbar = HomeToolbar()
> -        self._toolbar.connect('query-changed', self.__toolbar_query_changed_cb)
> -        self._toolbar.connect('view-changed', self.__toolbar_view_changed_cb)
> -        self.pack_start(self._toolbar, expand=False)
> -        self._toolbar.show()
> +        toolbar.connect('query-changed', self.__toolbar_query_changed_cb)
> +        toolbar.connect('view-changed', self.__toolbar_view_changed_cb)
>
>          self._set_view(_FAVORITES_VIEW)
>          self._query = ''
> @@ -139,107 +134,8 @@ class HomeBox(gtk.VBox):
>          #return self._donut.has_activities()
>          return False
>
> -    def focus_search_entry(self):
> -        self._toolbar.search_entry.grab_focus()
> -
>      def set_resume_mode(self, resume_mode):
>          self._favorites_box.set_resume_mode(resume_mode)
>          if resume_mode and self._query != '':
>              self._list_view.set_filter(self._query)
>              self._favorites_box.set_filter(self._query)
> -
> -
> -class HomeToolbar(ViewToolbar):
> -    __gtype_name__ = 'SugarHomeToolbar'
> -
> -    __gsignals__ = {
> -        'view-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
> -                         ([object])),
> -    }
> -
> -    def __init__(self):
> -        ViewToolbar.__init__(self)
> -
> -        favorites_button = FavoritesButton()
> -        favorites_button.connect('toggled', self.__view_button_toggled_cb,
> -                                 _FAVORITES_VIEW)
> -        self.insert(favorites_button, -1)
> -        favorites_button.show()
> -
> -        self._list_button = RadioToolButton(named_icon='view-list')
> -        self._list_button.props.group = favorites_button
> -        self._list_button.props.tooltip = _('List view')
> -        self._list_button.props.accelerator = _('<Ctrl>2')
> -        self._list_button.connect('toggled', self.__view_button_toggled_cb,
> -                            _LIST_VIEW)
> -        self.insert(self._list_button, -1)
> -        self._list_button.show()
> -
> -        self._add_separator()
> -
> -    def __view_button_toggled_cb(self, button, view):
> -        if button.props.active:
> -            self.search_entry.grab_focus()
> -            self.emit('view-changed', view)
> -
> -    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()
> -
> -
> -class FavoritesButton(RadioToolButton):
> -    __gtype_name__ = 'SugarFavoritesButton'
> -
> -    def __init__(self):
> -        RadioToolButton.__init__(self)
> -
> -        self.props.tooltip = _('Favorites view')
> -        self.props.accelerator = _('<Ctrl>1')
> -        self.props.group = None
> -
> -        favorites_settings = favoritesview.get_settings()
> -        self._layout = favorites_settings.layout
> -        self._update_icon()
> -
> -        # someday, this will be a gtk.Table()
> -        layouts_grid = gtk.HBox()
> -        layout_item = None
> -        for layoutid, layoutclass in sorted(favoritesview.LAYOUT_MAP.items()):
> -            layout_item = RadioToolButton(icon_name=layoutclass.icon_name,
> -                                          group=layout_item, active=False)
> -            if layoutid == self._layout:
> -                layout_item.set_active(True)
> -            layouts_grid.pack_start(layout_item, fill=False)
> -            layout_item.connect('toggled', self.__layout_activate_cb,
> -                                layoutid)
> -        layouts_grid.show_all()
> -        self.props.palette.set_content(layouts_grid)
> -
> -    def __layout_activate_cb(self, menu_item, layout):
> -        if not menu_item.get_active():
> -            return
> -        if self._layout == layout and self.props.active:
> -            return
> -
> -        if self._layout != layout:
> -            self._layout = layout
> -            self._update_icon()
> -
> -            favorites_settings = favoritesview.get_settings()
> -            favorites_settings.layout = layout
> -
> -        if not self.props.active:
> -            self.props.active = True
> -        else:
> -            self.emit('toggled')
> -
> -    def _update_icon(self):
> -        self.props.named_icon = favoritesview.LAYOUT_MAP[self._layout]\
> -                                .icon_name
> diff --git a/src/jarabe/desktop/homewindow.py b/src/jarabe/desktop/homewindow.py
> index 64eb48e..c4f1401 100644
> --- a/src/jarabe/desktop/homewindow.py
> +++ b/src/jarabe/desktop/homewindow.py
> @@ -26,6 +26,7 @@ from jarabe.desktop.meshbox import MeshBox
>  from jarabe.desktop.homebox import HomeBox
>  from jarabe.desktop.groupbox import GroupBox
>  from jarabe.desktop.transitionbox import TransitionBox
> +from jarabe.desktop.viewtoolbar import ViewToolbar
>  from jarabe.model.shell import ShellModel
>  from jarabe.model import shell
>
> @@ -67,13 +68,23 @@ class HomeWindow(gtk.Window):
>          self.connect('key-press-event', self.__key_press_event_cb)
>          self.connect('key-release-event', self.__key_release_event_cb)
>
> -        self._home_box = HomeBox()
> -        self._group_box = GroupBox()
> -        self._mesh_box = MeshBox()
> -        self._transition_box = TransitionBox()
> +        self._box = gtk.VBox()
> +
> +        self._toolbar = ViewToolbar()
> +        self._box.pack_start(self._toolbar, expand=False)
> +        self._toolbar.show()
>
> -        self.add(self._home_box)
> +        self._home_box = HomeBox(self._toolbar)
> +        self._box.pack_start(self._home_box)
>          self._home_box.show()
> +        self._toolbar.show_view_buttons()
> +
> +        self._group_box = GroupBox(self._toolbar)
> +        self._mesh_box = MeshBox(self._toolbar)
> +        self._transition_box = TransitionBox()
> +
> +        self.add(self._box)
> +        self._box.show()
>
>          self._transition_box.connect('completed',
>                                       self._transition_completed_cb)
> @@ -143,8 +154,10 @@ class HomeWindow(gtk.Window):
>
>          if old_level != ShellModel.ZOOM_ACTIVITY and \
>             new_level != ShellModel.ZOOM_ACTIVITY:
> -            self.remove(self.get_child())
> -            self.add(self._transition_box)
> +            children = self._box.get_children()
> +            if len(children) >= 2:
> +                self._box.remove(children[1])
> +            self._box.pack_start(self._transition_box)
>              self._transition_box.show()
>
>              if new_level == ShellModel.ZOOM_HOME:
> @@ -172,21 +185,25 @@ class HomeWindow(gtk.Window):
>          if level == ShellModel.ZOOM_ACTIVITY:
>              return
>
> -        current_child = self.get_child()
> -        self.remove(current_child)
> +        children = self._box.get_children()
> +        if len(children) >= 2:
> +            self._box.remove(children[1])
>
>          if level == ShellModel.ZOOM_HOME:
> -            self.add(self._home_box)
> +            self._box.pack_start(self._home_box)
>              self._home_box.show()
> -            self._home_box.focus_search_entry()
> +            self._toolbar.search_entry.grab_focus()
> +            self._toolbar.show_view_buttons()
>          elif level == ShellModel.ZOOM_GROUP:
> -            self.add(self._group_box)
> +            self._box.pack_start(self._group_box)
>              self._group_box.show()
> -            self._group_box.focus_search_entry()
> +            self._toolbar.search_entry.grab_focus()
> +            self._toolbar.hide_view_buttons()
>          elif level == ShellModel.ZOOM_MESH:
> -            self.add(self._mesh_box)
> +            self._box.pack_start(self._mesh_box)
>              self._mesh_box.show()
> -            self._mesh_box.focus_search_entry()
> +            self._toolbar.search_entry.grab_focus()
> +            self._toolbar.hide_view_buttons()
>
>      def get_home_box(self):
>          return self._home_box
> diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
> index 8002a33..1ee5e67 100644
> --- a/src/jarabe/desktop/meshbox.py
> +++ b/src/jarabe/desktop/meshbox.py
> @@ -41,7 +41,6 @@ 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
> @@ -52,6 +51,8 @@ from jarabe.journal import misc
>  _AP_ICON_NAME = 'network-wireless'
>  _OLPC_MESH_ICON_NAME = 'network-mesh'
>
> +_FILTERED_ALPHA = 0.33
> +
>
>  class _ActivityIcon(EventIcon):
>      def __init__(self, model, file_name, xo_color,
> @@ -335,10 +336,12 @@ class NetworkManagerObserver(object):
>                          self._box.add_adhoc_networks(device)
>
>
> -class MeshContainer(ViewContainer):
> -    __gtype_name__ = 'SugarMeshContainer'
> +class MeshBox(ViewContainer):
> +    __gtype_name__ = 'SugarMeshBox'
> +
> +    def __init__(self, toolbar):
> +        logging.debug('STARTUP: Loading the mesh view')
>
> -    def __init__(self):
>          layout = SpreadLayout()
>
>          # Round off icon size to an even number to ensure that the icon
> @@ -346,15 +349,6 @@ class MeshContainer(ViewContainer):
>                                 style.STANDARD_ICON_SIZE & ~1)
>          ViewContainer.__init__(self, layout, owner_icon)
>
> -
> -class MeshBox(gtk.VBox):
> -    __gtype_name__ = 'SugarMeshBox'
> -
> -    def __init__(self):
> -        logging.debug('STARTUP: Loading the mesh view')
> -
> -        gtk.VBox.__init__(self)
> -
>          self.wireless_networks = {}
>          self._adhoc_manager = None
>          self._adhoc_networks = []
> @@ -367,14 +361,7 @@ class MeshBox(gtk.VBox):
>          self._suspended = True
>          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._mesh_container = MeshContainer()
> -        self.add(self._mesh_container)
> -        self._mesh_container.show()
> +        toolbar.connect('query-changed', self._toolbar_query_changed_cb)
>
>          for buddy_model in self._model.get_buddies():
>              self._add_buddy(buddy_model)
> @@ -411,7 +398,7 @@ class MeshBox(gtk.VBox):
>          if buddy_model.is_owner():
>              return
>          icon = BuddyIcon(buddy_model)
> -        self._mesh_container.add(icon)
> +        self.add(icon)
>          icon.show()
>
>          if hasattr(icon, 'set_filter'):
> @@ -422,7 +409,7 @@ class MeshBox(gtk.VBox):
>      def _remove_buddy(self, buddy_model):
>          logging.debug('MeshBox._remove_buddy')
>          icon = self._buddies[buddy_model.props.key]
> -        self._mesh_container.remove(icon)
> +        self.remove(icon)
>          del self._buddies[buddy_model.props.key]
>
>      def __buddy_notify_current_activity_cb(self, buddy_model, pspec):
> @@ -436,7 +423,7 @@ class MeshBox(gtk.VBox):
>
>      def _add_activity(self, activity_model):
>          icon = ActivityView(activity_model)
> -        self._mesh_container.add(icon)
> +        self.add(icon)
>          icon.show()
>
>          if hasattr(icon, 'set_filter'):
> @@ -446,7 +433,7 @@ class MeshBox(gtk.VBox):
>
>      def _remove_activity(self, activity_model):
>          icon = self._activities[activity_model.activity_id]
> -        self._mesh_container.remove(icon)
> +        self.remove(icon)
>          del self._activities[activity_model.activity_id]
>
>      # add AP to its corresponding network icon on the desktop,
> @@ -459,7 +446,7 @@ class MeshBox(gtk.VBox):
>              # this is a new network
>              icon = WirelessNetworkView(ap)
>              self.wireless_networks[hash_value] = icon
> -            self._mesh_container.add(icon)
> +            self.add(icon)
>              icon.show()
>              if hasattr(icon, 'set_filter'):
>                  icon.set_filter(self._query)
> @@ -468,7 +455,7 @@ class MeshBox(gtk.VBox):
>          # remove a network if it has no APs left
>          if net.num_aps() == 0:
>              net.disconnect()
> -            self._mesh_container.remove(net)
> +            self.remove(net)
>              del self.wireless_networks[hash_value]
>
>      def _ap_props_changed_cb(self, ap, old_hash_value):
> @@ -546,19 +533,19 @@ class MeshBox(gtk.VBox):
>
>      def remove_adhoc_networks(self):
>          for icon in self._adhoc_networks:
> -            self._mesh_container.remove(icon)
> +            self.remove(icon)
>          self._adhoc_networks = []
>          self._adhoc_manager.stop_listening()
>
>      def _add_adhoc_network_icon(self, channel):
>          icon = SugarAdhocView(channel)
> -        self._mesh_container.add(icon)
> +        self.add(icon)
>          icon.show()
>          self._adhoc_networks.append(icon)
>
>      def _add_olpc_mesh_icon(self, mesh_mgr, channel):
>          icon = OlpcMeshView(mesh_mgr, channel)
> -        self._mesh_container.add(icon)
> +        self.add(icon)
>          icon.show()
>          self._mesh.append(icon)
>
> @@ -577,13 +564,13 @@ class MeshBox(gtk.VBox):
>              logging.debug('removing OLPC mesh IBSS')
>              net.remove_all_aps()
>              net.disconnect()
> -            self._mesh_container.remove(net)
> +            self.remove(net)
>              del self.wireless_networks[hash_value]
>
>      def disable_olpc_mesh(self, mesh_device):
>          for icon in self._mesh:
>              icon.disconnect()
> -            self._mesh_container.remove(icon)
> +            self.remove(icon)
>          self._mesh = []
>
>      def suspend(self):
> @@ -600,9 +587,6 @@ class MeshBox(gtk.VBox):
>
>      def _toolbar_query_changed_cb(self, toolbar, query):
>          self._query = query.lower()
> -        for icon in self._mesh_container.get_children():
> +        for icon in self.get_children():
>              if hasattr(icon, 'set_filter'):
>                  icon.set_filter(self._query)
> -
> -    def focus_search_entry(self):
> -        self._toolbar.search_entry.grab_focus()
> diff --git a/src/jarabe/desktop/transitionbox.py b/src/jarabe/desktop/transitionbox.py
> index 54a70de..3718bdd 100644
> --- a/src/jarabe/desktop/transitionbox.py
> +++ b/src/jarabe/desktop/transitionbox.py
> @@ -21,6 +21,8 @@ from sugar.graphics import animator
>
>  from jarabe.model.buddy import get_owner_instance
>  from jarabe.view.buddyicon import BuddyIcon
> +from jarabe.desktop.viewcontainer import ViewContainer
> +from jarabe.desktop.favoriteslayout import SpreadLayout
>
>
>  class _Animation(animator.Animation):
> @@ -36,7 +38,7 @@ class _Animation(animator.Animation):
>          self._icon.props.pixel_size = int(self.start_size + d)
>
>
> -class TransitionBox(BuddyIcon):
> +class TransitionBox(ViewContainer):
>      __gtype_name__ = 'SugarTransitionBox'
>
>      __gsignals__ = {
> @@ -44,8 +46,12 @@ class TransitionBox(BuddyIcon):
>      }
>
>      def __init__(self):
> -        BuddyIcon.__init__(self, buddy=get_owner_instance(),
> -                           pixel_size=style.XLARGE_ICON_SIZE)
> +        layout = SpreadLayout()
> +
> +        # Round off icon size to an even number to ensure that the icon
> +        self._owner_icon = BuddyIcon(buddy=get_owner_instance(),
> +                                     pixel_size=style.XLARGE_ICON_SIZE & ~1)
> +        ViewContainer.__init__(self, layout, self._owner_icon)
>
>          self._animator = animator.Animator(0.3)
>          self._animator.connect('completed', self._animation_completed_cb)
> @@ -55,5 +61,5 @@ class TransitionBox(BuddyIcon):
>
>      def start_transition(self, start_size, end_size):
>          self._animator.remove_all()
> -        self._animator.add(_Animation(self, start_size, end_size))
> +        self._animator.add(_Animation(self._owner_icon, start_size, end_size))
>          self._animator.start()
> diff --git a/src/jarabe/desktop/viewtoolbar.py b/src/jarabe/desktop/viewtoolbar.py
> index 9db301a..f0e3943 100644
> --- a/src/jarabe/desktop/viewtoolbar.py
> +++ b/src/jarabe/desktop/viewtoolbar.py
> @@ -17,6 +17,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
>
>  import gtk
> @@ -24,9 +25,13 @@ import gobject
>
>  from sugar.graphics import style
>  from sugar.graphics import iconentry
> +from sugar.graphics.radiotoolbutton import RadioToolButton
> +
> +from jarabe.desktop import favoritesview
>
>  _AUTOSEARCH_TIMEOUT = 1000
> -_FILTERED_ALPHA = 0.33
> +_FAVORITES_VIEW = 0
> +_LIST_VIEW = 1
>
>
>  class ViewToolbar(gtk.Toolbar):
> @@ -35,6 +40,8 @@ class ViewToolbar(gtk.Toolbar):
>      __gsignals__ = {
>          'query-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
>                            ([str])),
> +        'view-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
> +                         ([object])),
>      }
>
>      def __init__(self):
> @@ -61,6 +68,30 @@ class ViewToolbar(gtk.Toolbar):
>
>          self._add_separator(expand=True)
>
> +        self._favorites_button = FavoritesButton()
> +        self._favorites_button.connect('toggled',
> +                                       self.__view_button_toggled_cb,
> +                                       _FAVORITES_VIEW)
> +        self.insert(self._favorites_button, -1)
> +
> +        self._list_button = RadioToolButton(named_icon='view-list')
> +        self._list_button.props.group = self._favorites_button
> +        self._list_button.props.tooltip = _('List view')
> +        self._list_button.props.accelerator = _('<Ctrl>2')
> +        self._list_button.connect('toggled', self.__view_button_toggled_cb,
> +                                      _LIST_VIEW)
> +        self.insert(self._list_button, -1)
> +
> +        self._add_separator()
> +
> +    def show_view_buttons(self):
> +        self._favorites_button.show()
> +        self._list_button.show()
> +
> +    def hide_view_buttons(self):
> +        self._favorites_button.hide()
> +        self._list_button.hide()
> +
>      def _add_separator(self, expand=False):
>          separator = gtk.SeparatorToolItem()
>          separator.props.draw = False
> @@ -95,3 +126,59 @@ class ViewToolbar(gtk.Toolbar):
>          self._autosearch_timer = None
>          self.search_entry.activate()
>          return False
> +
> +    def __view_button_toggled_cb(self, button, view):
> +        if button.props.active:
> +            self.search_entry.grab_focus()
> +            self.emit('view-changed', view)
> +
> +
> +class FavoritesButton(RadioToolButton):
> +    __gtype_name__ = 'SugarFavoritesButton'
> +
> +    def __init__(self):
> +        RadioToolButton.__init__(self)
> +
> +        self.props.tooltip = _('Favorites view')
> +        self.props.accelerator = _('<Ctrl>1')
> +        self.props.group = None
> +
> +        favorites_settings = favoritesview.get_settings()
> +        self._layout = favorites_settings.layout
> +        self._update_icon()
> +
> +        # someday, this will be a gtk.Table()
> +        layouts_grid = gtk.HBox()
> +        layout_item = None
> +        for layoutid, layoutclass in sorted(favoritesview.LAYOUT_MAP.items()):
> +            layout_item = RadioToolButton(icon_name=layoutclass.icon_name,
> +                                          group=layout_item, active=False)
> +            if layoutid == self._layout:
> +                layout_item.set_active(True)
> +            layouts_grid.pack_start(layout_item, fill=False)
> +            layout_item.connect('toggled', self.__layout_activate_cb,
> +                                layoutid)
> +        layouts_grid.show_all()
> +        self.props.palette.set_content(layouts_grid)
> +
> +    def __layout_activate_cb(self, menu_item, layout):
> +        if not menu_item.get_active():
> +            return
> +        if self._layout == layout and self.props.active:
> +            return
> +
> +        if self._layout != layout:
> +            self._layout = layout
> +            self._update_icon()
> +
> +            favorites_settings = favoritesview.get_settings()
> +            favorites_settings.layout = layout
> +
> +        if not self.props.active:
> +            self.props.active = True
> +        else:
> +            self.emit('toggled')
> +
> +    def _update_icon(self):
> +        self.props.named_icon = favoritesview.LAYOUT_MAP[self._layout]\
> +                                .icon_name
> --
> 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