[Sugar-devel] [PATCH shell] Fix drag and drop in favourites view and grid intersections - SL #3960

Manuel Quiñones manuq at laptop.org
Thu Oct 4 11:40:42 EDT 2012


This fixes the unported API for drag-and-drop in favourites view.  And
in the grid, it fixes the collision detection, in GTK+3 we need to use
Gdk.Rectangle objects instead of tuples with the rectangle definition.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 src/jarabe/desktop/favoriteslayout.py |  3 +++
 src/jarabe/desktop/favoritesview.py   | 14 +++++++++-----
 src/jarabe/desktop/grid.py            | 25 ++++++++++++++++---------
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/jarabe/desktop/favoriteslayout.py b/src/jarabe/desktop/favoriteslayout.py
index eb5deef..c2bf8f5 100644
--- a/src/jarabe/desktop/favoriteslayout.py
+++ b/src/jarabe/desktop/favoriteslayout.py
@@ -124,6 +124,9 @@ class ViewLayout(Layout):
     def allocate_children(self, allocation, children):
         pass
 
+    def move_icon(self, child, x, y, allocation):
+        pass
+
     def move(self, child, x, y, allocation=None):
         self._grid.move(child, x / _CELL_SIZE, y / _CELL_SIZE, locked=True)
         child_request = child.size_request()
diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index 17d014e..cfe18eb 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -24,6 +24,7 @@ from gi.repository import GConf
 import glib
 from gi.repository import Gtk
 from gi.repository import Gdk
+from gi.repository import GdkPixbuf
 
 from sugar3.graphics import style
 from sugar3.graphics.icon import Icon
@@ -208,7 +209,9 @@ class FavoritesView(ViewContainer):
                                        int(x),
                                        int(y)):
             self._dragging = True
-            context_ = widget.drag_begin([_ICON_DND_TARGET],
+            target_entry = Gtk.TargetEntry.new(*_ICON_DND_TARGET)
+            target_list = Gtk.TargetList.new([target_entry])
+            context_ = widget.drag_begin(target_list,
                                          Gdk.DragAction.MOVE,
                                          1,
                                          event)
@@ -219,18 +222,19 @@ class FavoritesView(ViewContainer):
 
         self._hot_x = pixbuf.props.width / 2
         self._hot_y = pixbuf.props.height / 2
-        context.set_icon_pixbuf(pixbuf, self._hot_x, self._hot_y)
+        Gtk.drag_set_icon_pixbuf(context, pixbuf, self._hot_x, self._hot_y)
 
     def __drag_motion_cb(self, widget, context, x, y, time):
         if self._last_clicked_icon is not None:
-            context.drag_status(context.suggested_action, time)
+            Gdk.drag_status(context, context.get_suggested_action(), time)
             return True
         else:
             return False
 
     def __drag_drop_cb(self, widget, context, x, y, time):
         if self._last_clicked_icon is not None:
-            self.drag_get_data(context, _ICON_DND_TARGET[0])
+            target = Gdk.Atom.intern_static_string(_ICON_DND_TARGET[0])
+            self.drag_get_data(context, target, time)
             self._layout.move_icon(self._last_clicked_icon,
                                    x - self._hot_x, y - self._hot_y,
                                    self.get_allocation())
@@ -249,7 +253,7 @@ class FavoritesView(ViewContainer):
 
     def __drag_data_received_cb(self, widget, context, x, y, selection_data,
                                 info, time):
-        context.drop_finish(success=True, time=time)
+        Gdk.drop_finish(context, success=True, time_=time)
 
     def __connect_to_bundle_registry_cb(self):
         registry = bundleregistry.get_registry()
diff --git a/src/jarabe/desktop/grid.py b/src/jarabe/desktop/grid.py
index 851c23e..9d6d820 100644
--- a/src/jarabe/desktop/grid.py
+++ b/src/jarabe/desktop/grid.py
@@ -114,39 +114,45 @@ class Grid(SugarExt.Grid):
 
         new_rects = []
 
+        def _create_rectangle(x, y, width, height):
+            rect = Gdk.Rectangle()
+            rect.x, rect.y = x, y
+            rect.width, rect.height = width, height
+            return rect
+
         # Get rects right, left, bottom and top
         if (rect.x + rect.width < self.width - 1):
-            new_rects.append((rect.x + 1, rect.y,
+            new_rects.append(_create_rectangle(rect.x + 1, rect.y,
                                                rect.width, rect.height))
 
         if (rect.x - 1 > 0):
-            new_rects.append((rect.x - 1, rect.y,
+            new_rects.append(_create_rectangle(rect.x - 1, rect.y,
                                                rect.width, rect.height))
 
         if (rect.y + rect.height < self.height - 1):
-            new_rects.append((rect.x, rect.y + 1,
+            new_rects.append(_create_rectangle(rect.x, rect.y + 1,
                                                rect.width, rect.height))
 
         if (rect.y - 1 > 0):
-            new_rects.append((rect.x, rect.y - 1,
+            new_rects.append(_create_rectangle(rect.x, rect.y - 1,
                                                rect.width, rect.height))
 
         # Get diagonal rects
         if rect.x + rect.width < self.width - 1 and \
                 rect.y + rect.height < self.height - 1:
-            new_rects.append((rect.x + 1, rect.y + 1,
+            new_rects.append(_create_rectangle(rect.x + 1, rect.y + 1,
                                                rect.width, rect.height))
 
         if rect.x - 1 > 0 and rect.y + rect.height < self.height - 1:
-            new_rects.append((rect.x - 1, rect.y + 1,
+            new_rects.append(_create_rectangle(rect.x - 1, rect.y + 1,
                                                rect.width, rect.height))
 
         if rect.x + rect.width < self.width - 1 and rect.y - 1 > 0:
-            new_rects.append((rect.x + 1, rect.y - 1,
+            new_rects.append(_create_rectangle(rect.x + 1, rect.y - 1,
                                                rect.width, rect.height))
 
         if rect.x - 1 > 0 and rect.y - 1 > 0:
-            new_rects.append((rect.x - 1, rect.y - 1,
+            new_rects.append(_create_rectangle(rect.x - 1, rect.y - 1,
                                                rect.width, rect.height))
 
         random.shuffle(new_rects)
@@ -192,7 +198,8 @@ class Grid(SugarExt.Grid):
         collision_found = False
         child_rect = self._child_rects[child]
         for c in self._children:
-            intersects_, intersection = child_rect.intersect(self._child_rects[c])
+            intersects_, intersection = Gdk.rectangle_intersect(
+                child_rect, self._child_rects[c])
             if c != child and intersection.width > 0:
                 if (c not in self._locked_children and
                     c not in self._collisions):
-- 
1.7.11.4



More information about the Sugar-devel mailing list