From 4960ddae252c6b6a41a510b8963d026d9e9b13bc Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 14 Mar 2007 03:19:24 +0100 Subject: [PATCH] Adapt to the new hippo canvas sizing API --- shell/view/frame/framepopupcontext.py | 4 +++- sugar/graphics/canvasicon.py | 8 ++++---- sugar/graphics/optionmenu.py | 10 ---------- sugar/graphics/snowflakebox.py | 16 +++++++--------- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/shell/view/frame/framepopupcontext.py b/shell/view/frame/framepopupcontext.py index 63304cc1..34a57fe5 100644 --- a/shell/view/frame/framepopupcontext.py +++ b/shell/view/frame/framepopupcontext.py @@ -32,7 +32,9 @@ class FramePopupContext(PopupContext): def get_position(self, control, popup): [item_x, item_y] = control.get_context().translate_to_screen(control) [item_w, item_h] = control.get_allocation() - [popup_w, popup_h] = popup.get_request() + + [popup_w, natural_w] = popup.get_width_request() + [popup_h, natural_h] = popup.get_height_request(popup_w) left_x = item_x + item_w left_y = item_y diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 26b2357f..03b0d2be 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -327,11 +327,11 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): def do_get_content_width_request(self): [width, height] = self._get_icon_size() - return width + return (width, width) def do_get_content_height_request(self, for_width): [width, height] = self._get_icon_size() - return height + return (height, height) def do_button_press_event(self, event): self.emit_activated() @@ -373,8 +373,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): [x, y] = context.translate_to_screen(self) # TODO: Any better place to do this? - popup.props.box_width = max(popup.get_width_request(), - self.get_width_request()) + [min_width, natural_width] = self.get_width_request() + popup.props.box_width = max(popup.get_width_request(), min_width) [width, height] = self.get_allocation() y += height diff --git a/sugar/graphics/optionmenu.py b/sugar/graphics/optionmenu.py index 3ffaf4af..197669fc 100644 --- a/sugar/graphics/optionmenu.py +++ b/sugar/graphics/optionmenu.py @@ -104,16 +104,6 @@ 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() diff --git a/sugar/graphics/snowflakebox.py b/sugar/graphics/snowflakebox.py index f0d446c2..540b8b09 100644 --- a/sugar/graphics/snowflakebox.py +++ b/sugar/graphics/snowflakebox.py @@ -72,17 +72,15 @@ class SnowflakeBox(hippo.CanvasBox, hippo.CanvasItem): max_child_size = 0 for child in self.get_children(): - width = child.get_width_request() - height = child.get_height_request(width) - max_child_size = max (max_child_size, width) - max_child_size = max (max_child_size, height) + [min_w, natural_w] = child.get_width_request() + [min_h, natural_h] = child.get_height_request(width) + max_child_size = max (max_child_size, min_w) + max_child_size = max (max_child_size, min_h) - return self._get_radius() * 2 + \ - max_child_size + _FLAKE_DISTANCE * 2 + width = self._get_radius() * 2 + \ + max_child_size + _FLAKE_DISTANCE * 2 - def do_get_height_request(self, width): - hippo.CanvasBox.do_get_height_request(self, width) - return width + return [width, width] def do_allocate(self, width, height, origin_changed): hippo.CanvasBox.do_allocate(self, width, height, origin_changed)