Ticket #2220: 0001-Accelerators-doesn-t-work-if-toolitems-are-in-sub-pa.patch

File 0001-Accelerators-doesn-t-work-if-toolitems-are-in-sub-pa.patch, 3.2 KB (added by alsroot, 11 years ago)
  • src/sugar/graphics/toolbarbox.py

    From 4c1ec241f584adffc23af3fd5fa458017b081fd2 Mon Sep 17 00:00:00 2001
    From: Aleksey Lim <alsroot@member.fsf.org>
    Date: Sun, 22 Aug 2010 16:56:53 +0000
    Subject: [PATCH] Accelerators doesn't work if toolitems are in sub-pallete in ToolbarBox #2220
    
    ---
     src/sugar/graphics/toolbarbox.py |   13 +++++++++++++
     src/sugar/graphics/toolbutton.py |   15 ++++++++++-----
     2 files changed, 23 insertions(+), 5 deletions(-)
    
    diff --git a/src/sugar/graphics/toolbarbox.py b/src/sugar/graphics/toolbarbox.py
    index b674e8d..720fbd4 100644
    a b class ToolbarButton(ToolButton): 
    3636        self.connect('clicked',
    3737                lambda widget: self.set_expanded(not self.is_expanded()))
    3838
     39    def do_hierarchy_changed(self, previous_toplevel):
     40        # XXX Workaround for http://bugs.sugarlabs.org/ticket/2220
     41        # until implementing more robust scheme
     42
     43        def update_accelerator(parent):
     44            for child in parent.get_children():
     45                if hasattr(child, 'update_accelerator'):
     46                    child.update_accelerator(self.get_toplevel())
     47                if isinstance(child, gtk.Container):
     48                    update_accelerator(child)
     49
     50        update_accelerator(self.props.page)
     51
    3952    def get_toolbar_box(self):
    4053        if not hasattr(self.parent, 'owner'):
    4154            return None
  • src/sugar/graphics/toolbutton.py

    diff --git a/src/sugar/graphics/toolbutton.py b/src/sugar/graphics/toolbutton.py
    index f15e406..f2594ad 100644
    a b from sugar.graphics.icon import Icon 
    2929from sugar.graphics.palette import Palette, ToolInvoker
    3030
    3131
    32 def _add_accelerator(tool_button):
    33     if not tool_button.props.accelerator or not tool_button.get_toplevel() or \
     32def _add_accelerator(tool_button, toplevel):
     33    if not tool_button.props.accelerator or not toplevel or \
    3434            not tool_button.child:
    3535        return
    3636
    3737    # TODO: should we remove the accelerator from the prev top level?
    3838
    39     accel_group = tool_button.get_toplevel().get_data('sugar-accel-group')
     39    accel_group = toplevel.get_data('sugar-accel-group')
    4040    if not accel_group:
    4141        logging.warning('No gtk.AccelGroup in the top level window.')
    4242        return
    def _add_accelerator(tool_button): 
    4949
    5050
    5151def _hierarchy_changed_cb(tool_button, previous_toplevel):
    52     _add_accelerator(tool_button)
     52    _add_accelerator(tool_button, tool_button.get_toplevel())
    5353
    5454
    5555def setup_accelerator(tool_button):
    56     _add_accelerator(tool_button)
     56    _add_accelerator(tool_button, tool_button.get_toplevel())
    5757    tool_button.connect('hierarchy-changed', _hierarchy_changed_cb)
    5858
    5959
    class ToolButton(gtk.ToolButton): 
    105105    tooltip = gobject.property(type=str, setter=set_tooltip,
    106106        getter=get_tooltip)
    107107
     108    def update_accelerator(self, toplevel):
     109        # XXX Workaround for http://bugs.sugarlabs.org/ticket/2220
     110        # until implementing more robust scheme
     111        _add_accelerator(self, toplevel)
     112
    108113    def set_accelerator(self, accelerator):
    109114        self._accelerator = accelerator
    110115        setup_accelerator(self)