[Sugar-devel] [PATCH] Palette: get back horizontal padding as optional parameter - SL #4325

Manuel Quiñones manuq at laptop.org
Fri Apr 19 09:43:31 EDT 2013


The PaletteWindow lost the horizontal padding when it started to be
used as replacement of palette menus.  Bot other implementations like
the ColorButton palette need the padding.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 src/sugar3/graphics/colorbutton.py |  3 ++-
 src/sugar3/graphics/palette.py     | 18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/sugar3/graphics/colorbutton.py b/src/sugar3/graphics/colorbutton.py
index 3f205ff..299ef1b 100644
--- a/src/sugar3/graphics/colorbutton.py
+++ b/src/sugar3/graphics/colorbutton.py
@@ -255,7 +255,8 @@ class _ColorPalette(Palette):
         self.connect('popdown', self.__popdown_cb)
 
         self._picker_hbox = Gtk.HBox()
-        self.set_content(self._picker_hbox)
+        picker_padding = (0, 0, style.DEFAULT_SPACING, style.DEFAULT_SPACING)
+        self.set_content(self._picker_hbox, padding=picker_padding)
 
         self._swatch_tray = Gtk.Table()
 
diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py
index c6c00bc..085f557 100644
--- a/src/sugar3/graphics/palette.py
+++ b/src/sugar3/graphics/palette.py
@@ -321,10 +321,26 @@ class Palette(PaletteWindow):
                                     getter=get_icon_visible,
                                     setter=set_icon_visible)
 
-    def set_content(self, widget):
+    def set_content(self, widget, padding=None):
+        """Set widget as the content of the palette.
+
+        If padding is given, it should be a tuple (top, bottom, left,
+        right).
+
+        """
         assert self._widget is None \
                 or isinstance(self._widget, _PaletteWindowWidget)
 
+        if padding is not None:
+            # Wrap the widget in a Gtk.Alignment to set the given
+            # padding.
+            top, bottom, left, right = padding
+            alignment = Gtk.Alignment()
+            alignment.set_padding(top, bottom, left, right)
+            alignment.add(widget)
+            alignment.show()
+            widget = alignment
+
         if self._widget is None:
             self._widget = _PaletteWindowWidget(self)
             self._setup_widget()
-- 
1.8.1.4



More information about the Sugar-devel mailing list