From b84d5da31283c12d348a1ec80767c07c17ab5e63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
Date: Thu, 4 Oct 2012 12:34:02 -0300
Subject: [PATCH shell] Fix drag and drop in favourites view and grid
intersections - SL #3960
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
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@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
|
b
|
class ViewLayout(Layout): |
124 | 124 | def allocate_children(self, allocation, children): |
125 | 125 | pass |
126 | 126 | |
| 127 | def move_icon(self, child, x, y, allocation): |
| 128 | pass |
| 129 | |
127 | 130 | def move(self, child, x, y, allocation=None): |
128 | 131 | self._grid.move(child, x / _CELL_SIZE, y / _CELL_SIZE, locked=True) |
129 | 132 | child_request = child.size_request() |
diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index 17d014e..cfe18eb 100644
a
|
b
|
from gi.repository import GConf |
24 | 24 | import glib |
25 | 25 | from gi.repository import Gtk |
26 | 26 | from gi.repository import Gdk |
| 27 | from gi.repository import GdkPixbuf |
27 | 28 | |
28 | 29 | from sugar3.graphics import style |
29 | 30 | from sugar3.graphics.icon import Icon |
… |
… |
class FavoritesView(ViewContainer): |
208 | 209 | int(x), |
209 | 210 | int(y)): |
210 | 211 | self._dragging = True |
211 | | context_ = widget.drag_begin([_ICON_DND_TARGET], |
| 212 | target_entry = Gtk.TargetEntry.new(*_ICON_DND_TARGET) |
| 213 | target_list = Gtk.TargetList.new([target_entry]) |
| 214 | context_ = widget.drag_begin(target_list, |
212 | 215 | Gdk.DragAction.MOVE, |
213 | 216 | 1, |
214 | 217 | event) |
… |
… |
class FavoritesView(ViewContainer): |
219 | 222 | |
220 | 223 | self._hot_x = pixbuf.props.width / 2 |
221 | 224 | self._hot_y = pixbuf.props.height / 2 |
222 | | context.set_icon_pixbuf(pixbuf, self._hot_x, self._hot_y) |
| 225 | Gtk.drag_set_icon_pixbuf(context, pixbuf, self._hot_x, self._hot_y) |
223 | 226 | |
224 | 227 | def __drag_motion_cb(self, widget, context, x, y, time): |
225 | 228 | if self._last_clicked_icon is not None: |
226 | | context.drag_status(context.suggested_action, time) |
| 229 | Gdk.drag_status(context, context.get_suggested_action(), time) |
227 | 230 | return True |
228 | 231 | else: |
229 | 232 | return False |
230 | 233 | |
231 | 234 | def __drag_drop_cb(self, widget, context, x, y, time): |
232 | 235 | if self._last_clicked_icon is not None: |
233 | | self.drag_get_data(context, _ICON_DND_TARGET[0]) |
| 236 | target = Gdk.Atom.intern_static_string(_ICON_DND_TARGET[0]) |
| 237 | self.drag_get_data(context, target, time) |
234 | 238 | self._layout.move_icon(self._last_clicked_icon, |
235 | 239 | x - self._hot_x, y - self._hot_y, |
236 | 240 | self.get_allocation()) |
… |
… |
class FavoritesView(ViewContainer): |
249 | 253 | |
250 | 254 | def __drag_data_received_cb(self, widget, context, x, y, selection_data, |
251 | 255 | info, time): |
252 | | context.drop_finish(success=True, time=time) |
| 256 | Gdk.drop_finish(context, success=True, time_=time) |
253 | 257 | |
254 | 258 | def __connect_to_bundle_registry_cb(self): |
255 | 259 | registry = bundleregistry.get_registry() |
diff --git a/src/jarabe/desktop/grid.py b/src/jarabe/desktop/grid.py
index 851c23e..9d6d820 100644
a
|
b
|
class Grid(SugarExt.Grid): |
114 | 114 | |
115 | 115 | new_rects = [] |
116 | 116 | |
| 117 | def _create_rectangle(x, y, width, height): |
| 118 | rect = Gdk.Rectangle() |
| 119 | rect.x, rect.y = x, y |
| 120 | rect.width, rect.height = width, height |
| 121 | return rect |
| 122 | |
117 | 123 | # Get rects right, left, bottom and top |
118 | 124 | if (rect.x + rect.width < self.width - 1): |
119 | | new_rects.append((rect.x + 1, rect.y, |
| 125 | new_rects.append(_create_rectangle(rect.x + 1, rect.y, |
120 | 126 | rect.width, rect.height)) |
121 | 127 | |
122 | 128 | if (rect.x - 1 > 0): |
123 | | new_rects.append((rect.x - 1, rect.y, |
| 129 | new_rects.append(_create_rectangle(rect.x - 1, rect.y, |
124 | 130 | rect.width, rect.height)) |
125 | 131 | |
126 | 132 | if (rect.y + rect.height < self.height - 1): |
127 | | new_rects.append((rect.x, rect.y + 1, |
| 133 | new_rects.append(_create_rectangle(rect.x, rect.y + 1, |
128 | 134 | rect.width, rect.height)) |
129 | 135 | |
130 | 136 | if (rect.y - 1 > 0): |
131 | | new_rects.append((rect.x, rect.y - 1, |
| 137 | new_rects.append(_create_rectangle(rect.x, rect.y - 1, |
132 | 138 | rect.width, rect.height)) |
133 | 139 | |
134 | 140 | # Get diagonal rects |
135 | 141 | if rect.x + rect.width < self.width - 1 and \ |
136 | 142 | rect.y + rect.height < self.height - 1: |
137 | | new_rects.append((rect.x + 1, rect.y + 1, |
| 143 | new_rects.append(_create_rectangle(rect.x + 1, rect.y + 1, |
138 | 144 | rect.width, rect.height)) |
139 | 145 | |
140 | 146 | if rect.x - 1 > 0 and rect.y + rect.height < self.height - 1: |
141 | | new_rects.append((rect.x - 1, rect.y + 1, |
| 147 | new_rects.append(_create_rectangle(rect.x - 1, rect.y + 1, |
142 | 148 | rect.width, rect.height)) |
143 | 149 | |
144 | 150 | if rect.x + rect.width < self.width - 1 and rect.y - 1 > 0: |
145 | | new_rects.append((rect.x + 1, rect.y - 1, |
| 151 | new_rects.append(_create_rectangle(rect.x + 1, rect.y - 1, |
146 | 152 | rect.width, rect.height)) |
147 | 153 | |
148 | 154 | if rect.x - 1 > 0 and rect.y - 1 > 0: |
149 | | new_rects.append((rect.x - 1, rect.y - 1, |
| 155 | new_rects.append(_create_rectangle(rect.x - 1, rect.y - 1, |
150 | 156 | rect.width, rect.height)) |
151 | 157 | |
152 | 158 | random.shuffle(new_rects) |
… |
… |
class Grid(SugarExt.Grid): |
192 | 198 | collision_found = False |
193 | 199 | child_rect = self._child_rects[child] |
194 | 200 | for c in self._children: |
195 | | intersects_, intersection = child_rect.intersect(self._child_rects[c]) |
| 201 | intersects_, intersection = Gdk.rectangle_intersect( |
| 202 | child_rect, self._child_rects[c]) |
196 | 203 | if c != child and intersection.width > 0: |
197 | 204 | if (c not in self._locked_children and |
198 | 205 | c not in self._collisions): |