From dbe32ec7cfe896c0c99d8f2bf80ab7883eabbeff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Thu, 13 Sep 2012 00:39:55 -0300 Subject: [PATCH] Style the palette menu header - SL #3879 #3836 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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, because the icon was greyed out. This was to make it an informational, unclickeable item. I am making it look like an informational item in the theme instead. This has the problem that its still navigateable with keyboard and clickeable, so it has to be fixed later. Add a separator below the header. Is a custom class so it can be styled in the theme. Signed-off-by: Manuel QuiƱones Acked-by: Simon Schampijer --- src/sugar3/graphics/palette.py | 51 +++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py index 4bb72ce2..284c84b4 100644 --- a/src/sugar3/graphics/palette.py +++ b/src/sugar3/graphics/palette.py @@ -40,9 +40,40 @@ from sugar3.graphics.palettewindow import MouseSpeedDetector, Invoker, \ WidgetInvoker, CursorInvoker, ToolInvoker, CellRendererInvoker -class Palette(PaletteWindow): +class _HeaderItem(Gtk.MenuItem): + """A MenuItem with a custom child widget that gets all the + available space. + """ - Floating palette implementation. + + __gtype_name__ = 'SugarPaletteHeader' + + def __init__(self, widget): + Gtk.MenuItem.__init__(self) + if self.get_child() is not None: + self.remove(self.get_child()) + self.add(widget) + # FIXME we have to mark it as insensitive again to make it an + # informational element, when we realize how to get the icon + # displayed correctly - SL #3836 + # self.set_sensitive(False) + + def do_size_allocate(self, allocation): + self.set_allocation(allocation) + self.get_child().size_allocate(allocation) + + +class _HeaderSeparator(Gtk.SeparatorMenuItem): + """A SeparatorMenuItem that can be styled in the theme.""" + + __gtype_name__ = 'SugarPaletteHeaderSeparator' + + def __init__(self): + Gtk.SeparatorMenuItem.__init__(self) + + +class Palette(PaletteWindow): + """Floating palette implementation. This class dynamically switches between one of two encapsulated child widget types: a _PaletteWindowWidget or a _PaletteMenuWidget. @@ -375,20 +406,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