From 7a07bb10015e80fd34164da0d66ec54700df96df Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Wed, 18 Apr 2012 22:29:15 +0200 Subject: [PATCH] Draw accelerator in Palette SL #3459 The accelerator in the primary information in the Palette has not been drawn because there was not enough space reserved for it. The preferred size we get back for the Palette window does not include the accelerator of the Gtk.AccelLabel. We need to include that in our calculation for the Palette size. In order to make that information available which is part of the Palette class we need to pass the instance to the PaletteWindowWidget instance. Signed-off-by: Simon Schampijer Acked-by: Daniel Drake --- src/sugar3/graphics/palette.py | 15 +++++---------- src/sugar3/graphics/palettewindow.py | 14 ++++++++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py index 1f95c11a..4bb72ce2 100644 --- a/src/sugar3/graphics/palette.py +++ b/src/sugar3/graphics/palette.py @@ -301,7 +301,7 @@ class Palette(PaletteWindow): or isinstance(self._widget, _PaletteWindowWidget) if self._widget is None: - self._widget = _PaletteWindowWidget() + self._widget = _PaletteWindowWidget(self) self._setup_widget() self._palette_box = Gtk.VBox() @@ -327,16 +327,11 @@ class Palette(PaletteWindow): self._update_accept_focus() self._update_separators() - def do_get_preferred_width(self): - minimum, natural = PaletteWindow.do_get_preferred_width(self) - + def get_label_width(self): # Gtk.AccelLabel request doesn't include the accelerator. - label_width = self._label_alignment.size_request()[0] + \ - self._label.get_accel_width() + \ - 2 * self.get_border_width() - - width = max(minimum, label_width, self._full_request[0]) - return width, width + label_width = self._label_alignment.get_preferred_width()[1] + \ + self._label.get_accel_width() + return label_width def _update_separators(self): visible = self._content.get_children() diff --git a/src/sugar3/graphics/palettewindow.py b/src/sugar3/graphics/palettewindow.py index 47236efe..449f5500 100644 --- a/src/sugar3/graphics/palettewindow.py +++ b/src/sugar3/graphics/palettewindow.py @@ -239,9 +239,10 @@ class _PaletteWindowWidget(Gtk.Window): 'leave-notify': (GObject.SignalFlags.RUN_FIRST, None, ([])), } - def __init__(self): + def __init__(self, palette=None): Gtk.Window.__init__(self) + self._palette = palette self.set_decorated(False) self.set_resizable(False) self.set_position(Gtk.WindowPosition.NONE) @@ -270,11 +271,12 @@ class _PaletteWindowWidget(Gtk.Window): self.set_type_hint(Gdk.WindowTypeHint.DIALOG) def do_get_preferred_width(self): - size = 0 - child = self.get_child() - if child: - minimum_size, natural_size = child.get_preferred_width() - size = max(minimum_size, natural_size, style.GRID_CELL_SIZE * 2) + minimum, natural = Gtk.Window.do_get_preferred_width(self) + label_width = 0 + if self._palette is not None: + label_width = self._palette.get_label_width() + size = max(natural, label_width + 2 * self.get_border_width(), + style.GRID_CELL_SIZE * 2) return size, size def do_size_allocate(self, allocation):