[Commits] sugar-toolkit branch master updated.

Tomeu Vizoso tomeu at tomeuvizoso.net
Fri Dec 5 05:51:50 EST 2008


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "/home/olpc-code/git/sugar-toolkit".

The branch, master has been updated
       via  33e94723da52e34b5df0524f5b98e49fe4c9c238 (commit)
      from  5a0f5757183ddb9df55552af4a8524b96062730a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

 src/sugar/graphics/menuitem.py |   59 +++++++++++++++++++++++++++++++++++-----
 src/sugar/graphics/palette.py  |    4 +++
 2 files changed, 56 insertions(+), 7 deletions(-)

- Log -----------------------------------------------------------------
commit 33e94723da52e34b5df0524f5b98e49fe4c9c238
Author: Tomeu Vizoso <tomeu at tomeuvizoso.net>
Date:   Fri Dec 5 11:51:40 2008 +0100

    Add accelerator support to menu items

diff --git a/src/sugar/graphics/menuitem.py b/src/sugar/graphics/menuitem.py
index 70c08f7..fc77ba0 100644
--- a/src/sugar/graphics/menuitem.py
+++ b/src/sugar/graphics/menuitem.py
@@ -19,20 +19,65 @@
 STABLE.
 """
 
-import gtk
-from sugar.graphics.icon import Icon
+import logging
 
+import gobject
 import pango
+import gtk
+
+from sugar.graphics.icon import Icon
 
 class MenuItem(gtk.ImageMenuItem):
     def __init__(self, text_label=None, icon_name=None, text_maxlen=0):
-        gtk.ImageMenuItem.__init__(self, text_label)
+        gobject.GObject.__init__(self)
+        self._accelerator = None
+
+        label = gtk.AccelLabel(text_label)
+        label.set_alignment(0.0, 0.5)
+        label.set_accel_widget(self)
+        if text_maxlen > 0:
+            label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
+            label.set_max_width_chars(text_maxlen)
+        self.add(label)
+        label.show()
+
         if icon_name:
             icon = Icon(icon_name=icon_name, icon_size=gtk.ICON_SIZE_MENU)
             self.set_image(icon)
             icon.show()
 
-        if text_maxlen > 0:
-            child = self.get_child()
-            child.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
-            child.set_max_width_chars(text_maxlen)
+        self.connect('can-activate-accel', self.__can_activate_accel_cb)
+        self.connect('hierarchy-changed', self.__hierarchy_changed_cb)
+
+    def __hierarchy_changed_cb(self, widget, previous_toplevel):
+        self._add_accelerator()
+
+    def __can_activate_accel_cb(self, widget, signal_id):
+        # Accept activation via accelerators regardless of this widget's state
+        return True
+
+    def _add_accelerator(self):
+        if self._accelerator is None or self.get_toplevel() is None:
+            return
+
+        # TODO: should we remove the accelerator from the prev top level?
+
+        accel_group = self.get_toplevel().get_data('sugar-accel-group')
+        if not accel_group:
+            logging.warning('No gtk.AccelGroup in the top level window.')
+            return
+
+        keyval, mask = gtk.accelerator_parse(self._accelerator)
+        self.add_accelerator('activate', accel_group, keyval, mask,
+                             gtk.ACCEL_LOCKED | gtk.ACCEL_VISIBLE)
+
+    def set_accelerator(self, accelerator):
+        self._accelerator = accelerator
+        self._add_accelerator()
+
+    def get_accelerator(self):
+        return self._accelerator
+
+    accelerator = gobject.property(type=str, setter=set_accelerator,
+            getter=get_accelerator)
+
diff --git a/src/sugar/graphics/palette.py b/src/sugar/graphics/palette.py
index 706bc1c..5ddaca8 100644
--- a/src/sugar/graphics/palette.py
+++ b/src/sugar/graphics/palette.py
@@ -230,6 +230,10 @@ class Palette(gtk.Window):
         # Just assume xthickness and ythickness are the same
         self.set_border_width(self.get_style().xthickness)
 
+        accel_group = gtk.AccelGroup()
+        self.set_data('sugar-accel-group', accel_group)
+        self.add_accel_group(accel_group)
+
         primary_box.set_size_request(-1, style.zoom(style.GRID_CELL_SIZE)
                                      - 2 * self.get_border_width())
 
-----------------------------------------------------------------------


--
/home/olpc-code/git/sugar-toolkit


More information about the Commits mailing list