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):