From 6dc96bb7b4aafd3ef13e9eca4d433a1bc2e0e82b Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Sun, 30 Oct 2011 11:20:41 +0000 Subject: Icon: port to new Height-for-width Geometry Management GTK3 has replaced [1] the GTK2 geometry management with Height-for-width Geometry Management [2]. This means we need to replace size_request() methods with get_preferred_{width,height}(). [1] http://developer.gnome.org/gtk3/3.0/ch25s02.html#id1525688 [2] http://developer.gnome.org/gtk3/3.0/GtkWidget.html#geometry-management [assembled from several patches; fixed up left-over plus sign; added description] Signed-off-by: Sascha Silbe --- diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index 76af718..2a56523 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -362,27 +362,27 @@ class Icon(Gtk.Image): def _file_changed_cb(self, image, pspec): self._buffer.file_name = self.props.file - def do_size_request(self, requisition): - """ - Parameters - ---------- - requisition : - - Returns - ------- - None + def do_get_preferred_height(self): + self._sync_image_properties() + surface = self._buffer.get_surface() + if surface: + height = surface.get_height() + elif self._buffer.height: + height = self._buffer.height + else: + height = 0 + return (height, height) - """ + def do_get_preferred_width(self): self._sync_image_properties() surface = self._buffer.get_surface() if surface: - requisition[0] = surface.get_width() - requisition[1] = surface.get_height() - elif self._buffer.width and self._buffer.height: - requisition[0] = self._buffer.width - requisition[1] = self._buffer.width + width = surface.get_width() + elif self._buffer.width: + width = self._buffer.width else: - requisition[0] = requisition[1] = 0 + width = 0 + return (width, width) def do_expose_event(self, event): """ @@ -408,9 +408,9 @@ class Icon(Gtk.Image): xalign = 1.0 - xalign allocation = self.get_allocation() - x = math.floor(allocation.x + xpad + + x = math.floor(xpad + (allocation.width - requisition.width) * xalign) - y = math.floor(allocation.y + ypad + + y = math.floor(ypad + (allocation.height - requisition.height) * yalign) cr = self.get_window().cairo_create() -- cgit v0.9.1