From bba86e5b74ea70ecde1d3fbc8753ecff986e5226 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sun, 25 Feb 2007 14:58:18 +0100 Subject: [PATCH] First try at menu sizing in OptionMenu. --- sugar/graphics/optionmenu.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sugar/graphics/optionmenu.py b/sugar/graphics/optionmenu.py index f5a44175..2bb6fde4 100644 --- a/sugar/graphics/optionmenu.py +++ b/sugar/graphics/optionmenu.py @@ -68,10 +68,10 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._round_box.props.padding = units.points_to_pixels(1) self.append(self._round_box, hippo.PACK_EXPAND) - self._canvas_text = hippo.CanvasText() - self._canvas_text.props.text = _('No options') - self._canvas_text.props.color = color.LABEL_TEXT.get_int() - self._canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() + self._canvas_text = hippo.CanvasText(text=_('No options'), + color=color.LABEL_TEXT.get_int(), + font_desc=font.DEFAULT.get_pango_desc(), + xalign=hippo.ALIGNMENT_START) self._round_box.append(self._canvas_text, hippo.PACK_EXPAND) # TODO: Substitute for the right icon. @@ -102,6 +102,16 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._menu.add_item(menu_item) + def do_get_width_request(self): + max_width = max(self._canvas_text.do_get_content_width_request(self._canvas_text), + self._menu.do_get_content_width_request(self._menu)) + + self._canvas_text.props.box_width = max_width + + current_width = hippo.CanvasBox.do_get_width_request(self) + self._menu.props.box_width = current_width + return current_width + def add_separator(self): self._menu.add_separator() @@ -112,10 +122,6 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): context = self._round_box.get_context() [x, y] = context.translate_to_screen(self._round_box) - # TODO: Any better place to do this? - self._menu.props.box_width = max(self.get_width_request(), - self._menu.get_width_request()) - [width, height] = self._round_box.get_allocation() self._menu.popup(x, y + height)