[Sugar-devel] [PATCH sugar-toolkit-gtk3] Style the palette menu header - SL #3879 #3836

Manuel Quiñones manuq at laptop.org
Thu Sep 13 00:26:27 EDT 2012


- Make the first item of the menu a custom class, to make the children
  widget allocate using all the available space.  And so it can be
  styled in the theme.

- Remove the set_sensitive(False) from the header item, this was just
  for styling to make it look like an informational, unclickeable
  item.  But this will be done in the theme instead.

- Add a separator below the header.  Is a custom class so it can be
  styled in the theme.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 src/sugar3/graphics/palette.py | 44 +++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py
index 4bb72ce..8b98f9f 100644
--- a/src/sugar3/graphics/palette.py
+++ b/src/sugar3/graphics/palette.py
@@ -40,6 +40,34 @@ from sugar3.graphics.palettewindow import MouseSpeedDetector, Invoker, \
         WidgetInvoker, CursorInvoker, ToolInvoker, CellRendererInvoker
 
 
+class _HeaderItem(Gtk.MenuItem):
+    """
+    A MenuItem with a custom child widget that gets all the available
+    space.
+
+    """
+
+    __gtype_name__ = 'SugarPaletteHeader'
+
+    def __init__(self, widget):
+        super(_HeaderItem, self).__init__()
+        if self.get_child() is not None:
+            self.remove(self.get_child())
+        self.add(widget)
+
+    def do_size_allocate(self, allocation):
+        self.set_allocation(allocation)
+        self.get_child().size_allocate(allocation)
+
+
+class _HeaderSeparator(Gtk.SeparatorMenuItem):
+
+    __gtype_name__ = 'SugarPaletteHeaderSeparator'
+
+    def __init__(self):
+        super(_HeaderSeparator, self).__init__()
+
+
 class Palette(PaletteWindow):
     """
     Floating palette implementation.
@@ -375,20 +403,14 @@ class Palette(PaletteWindow):
 
             self._widget = _PaletteMenuWidget()
 
-            self._label_menuitem = Gtk.MenuItem()
-            child = self._label_menuitem.get_child()
-            if child is not None:
-                self._label_menuitem.remove(child)
-            self._label_menuitem.add(self._primary_box)
-
-            # Mark the menuitem as insensitive so that it appears as an
-            # informational element, rather than a clickable item in the menu.
-            # TODO: see if we can do this better in GTK.
-            self._label_menuitem.set_sensitive(False)
-
+            self._label_menuitem = _HeaderItem(self._primary_box)
             self._label_menuitem.show()
             self._widget.append(self._label_menuitem)
 
+            separator = _HeaderSeparator()
+            self._widget.append(separator)
+            separator.show()
+
             self._setup_widget()
 
         return self._widget
-- 
1.7.11.4



More information about the Sugar-devel mailing list