[Sugar-devel] [PATCH shell] Replace cairo.RectangleInt with Gdk.Rectangle

Simon Schampijer simon at schampijer.de
Wed Sep 12 07:06:30 EDT 2012


From: Simon Schampijer <simon at laptop.org>

The Gdk.Rectangle is basically a cairo.RectangleInt but that way we
do not need to import the dynamic cairo bindings explicitly.

Signed-off-by: Simon Schampijer <simon at laptop.org>
---
 src/jarabe/desktop/favoriteslayout.py | 15 +++++++--------
 src/jarabe/desktop/grid.py            |  6 +++---
 src/jarabe/frame/frameinvoker.py      |  3 +--
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/jarabe/desktop/favoriteslayout.py b/src/jarabe/desktop/favoriteslayout.py
index 13b5095..a367ab6 100644
--- a/src/jarabe/desktop/favoriteslayout.py
+++ b/src/jarabe/desktop/favoriteslayout.py
@@ -22,7 +22,6 @@ from gettext import gettext as _
 
 from gi.repository import Gtk
 from gi.repository import Gdk
-from gi.repository import cairo
 
 from sugar3.graphics import style
 
@@ -86,7 +85,7 @@ class ViewLayout(Layout):
         y -= owner_height / 2
 
         # calculate x coordinate and create allocation
-        owner_icon_allocation = cairo.RectangleInt()
+        owner_icon_allocation = Gdk.Rectangle()
         owner_icon_allocation.x = (width - owner_width) / 2
         owner_icon_allocation.y = allocation.y + y
         owner_icon_allocation.width = owner_width
@@ -107,7 +106,7 @@ class ViewLayout(Layout):
         # Position the current activity below the XO icon
         # FIXME must ensure we cross into next grid cell here..
         activity_request = activity_icon.size_request()
-        activity_icon_allocation = cairo.RectangleInt()
+        activity_icon_allocation = Gdk.Rectangle()
         activity_icon_allocation.x = (width - activity_request.width) / 2
         activity_icon_allocation.y = owner_icon_allocation.y + owner_height
         activity_icon_allocation.width = activity_request.width
@@ -130,7 +129,7 @@ class ViewLayout(Layout):
         child_request = child.size_request()
         rect = self._grid.get_child_rect(child)
 
-        child_allocation = cairo.RectangleInt()
+        child_allocation = Gdk.Rectangle()
         child_allocation.x = int(round(rect.x * _CELL_SIZE))
         child_allocation.y = int(round(rect.y * _CELL_SIZE))
         child_allocation.width = child_request.width
@@ -146,7 +145,7 @@ class ViewLayout(Layout):
     def __grid_child_changed_cb(self, grid, child):
         request = child.size_request()
         rect = self._grid.get_child_rect(child)
-        child_allocation = cairo.RectangleInt()
+        child_allocation = Gdk.Rectangle()
         child_allocation.x = int(round(rect.x * _CELL_SIZE))
         child_allocation.y = int(round(rect.y * _CELL_SIZE))
         child_allocation.width = request.width
@@ -175,7 +174,7 @@ class SpreadLayout(ViewLayout):
 
             requisition = child.size_request()
             rect = self._grid.get_child_rect(child)
-            child_allocation = cairo.RectangleInt()
+            child_allocation = Gdk.Rectangle()
             child_allocation.x = int(round(rect.x * _CELL_SIZE))
             child_allocation.y = int(round(rect.y * _CELL_SIZE)) + allocation.y
             child_allocation.width = requisition.width
@@ -248,7 +247,7 @@ class RandomLayout(SpreadLayout):
                                    x / _CELL_SIZE, y / _CELL_SIZE)
 
             rect = self._grid.get_child_rect(child)
-            child_allocation = cairo.RectangleInt()
+            child_allocation = Gdk.Rectangle()
             child_allocation.x = int(round(rect.x * _CELL_SIZE))
             child_allocation.y = int(round(rect.y * _CELL_SIZE)) + allocation.y
             child_allocation.width = child_requisition.width
@@ -380,7 +379,7 @@ class RingLayout(ViewLayout):
                                             allocation.height)
             child.size_request()
             child.set_size(icon_size)
-            child_allocation = cairo.RectangleInt()
+            child_allocation = Gdk.Rectangle()
             child_allocation.x = allocation.x + x
             child_allocation.y = allocation.y + y
             child_allocation.width = icon_size
diff --git a/src/jarabe/desktop/grid.py b/src/jarabe/desktop/grid.py
index aa7dce2..851c23e 100644
--- a/src/jarabe/desktop/grid.py
+++ b/src/jarabe/desktop/grid.py
@@ -19,7 +19,7 @@ import random
 
 from gi.repository import GObject
 from gi.repository import Gtk
-from gi.repository import cairo
+from gi.repository import Gdk
 
 from gi.repository import SugarExt
 
@@ -49,7 +49,7 @@ class Grid(SugarExt.Grid):
 
     def add(self, child, width, height, x=None, y=None, locked=False):
         if x is not None and y is not None:
-            rect = cairo.RectangleInt()
+            rect = Gdk.Rectangle()
             rect.x = x
             rect.y = y
             rect.width = width
@@ -59,7 +59,7 @@ class Grid(SugarExt.Grid):
             trials = _PLACE_TRIALS
             weight = _MAX_WEIGHT
             while trials > 0 and weight:
-                rect = cairo.RectangleInt()
+                rect = Gdk.Rectangle()
                 rect.x = int(random.random() * (self.width - width))
                 rect.y = int(random.random() * (self.height - height))
                 rect.width = width
diff --git a/src/jarabe/frame/frameinvoker.py b/src/jarabe/frame/frameinvoker.py
index a2d5fb2..b9cd11d 100644
--- a/src/jarabe/frame/frameinvoker.py
+++ b/src/jarabe/frame/frameinvoker.py
@@ -16,7 +16,6 @@
 
 from gi.repository import Gtk
 from gi.repository import Gdk
-from gi.repository import cairo
 
 from sugar3.graphics import style
 from sugar3.graphics.palette import WidgetInvoker
@@ -25,7 +24,7 @@ from sugar3.graphics.palette import WidgetInvoker
 def _get_screen_area():
     frame_thickness = style.GRID_CELL_SIZE
 
-    screen_area = cairo.RectangleInt()
+    screen_area = Gdk.Rectangle()
     screen_area.x = screen_area.y = frame_thickness
     screen_area.width = Gdk.Screen.width() - frame_thickness
     screen_area.height = Gdk.Screen.height() - frame_thickness
-- 
1.7.11.4



More information about the Sugar-devel mailing list