Ticket #3960: 0001-Fix-drag-and-drop-in-favourites-view-and-grid-inters.patch

File 0001-Fix-drag-and-drop-in-favourites-view-and-grid-inters.patch, 7.0 KB (added by manuq, 12 years ago)

Candidate patch.

  • src/jarabe/desktop/favoriteslayout.py

    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): 
    124124    def allocate_children(self, allocation, children):
    125125        pass
    126126
     127    def move_icon(self, child, x, y, allocation):
     128        pass
     129
    127130    def move(self, child, x, y, allocation=None):
    128131        self._grid.move(child, x / _CELL_SIZE, y / _CELL_SIZE, locked=True)
    129132        child_request = child.size_request()
  • src/jarabe/desktop/favoritesview.py

    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 
    2424import glib
    2525from gi.repository import Gtk
    2626from gi.repository import Gdk
     27from gi.repository import GdkPixbuf
    2728
    2829from sugar3.graphics import style
    2930from sugar3.graphics.icon import Icon
    class FavoritesView(ViewContainer): 
    208209                                       int(x),
    209210                                       int(y)):
    210211            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,
    212215                                         Gdk.DragAction.MOVE,
    213216                                         1,
    214217                                         event)
    class FavoritesView(ViewContainer): 
    219222
    220223        self._hot_x = pixbuf.props.width / 2
    221224        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)
    223226
    224227    def __drag_motion_cb(self, widget, context, x, y, time):
    225228        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)
    227230            return True
    228231        else:
    229232            return False
    230233
    231234    def __drag_drop_cb(self, widget, context, x, y, time):
    232235        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)
    234238            self._layout.move_icon(self._last_clicked_icon,
    235239                                   x - self._hot_x, y - self._hot_y,
    236240                                   self.get_allocation())
    class FavoritesView(ViewContainer): 
    249253
    250254    def __drag_data_received_cb(self, widget, context, x, y, selection_data,
    251255                                info, time):
    252         context.drop_finish(success=True, time=time)
     256        Gdk.drop_finish(context, success=True, time_=time)
    253257
    254258    def __connect_to_bundle_registry_cb(self):
    255259        registry = bundleregistry.get_registry()
  • src/jarabe/desktop/grid.py

    diff --git a/src/jarabe/desktop/grid.py b/src/jarabe/desktop/grid.py
    index 851c23e..9d6d820 100644
    a b class Grid(SugarExt.Grid): 
    114114
    115115        new_rects = []
    116116
     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
    117123        # Get rects right, left, bottom and top
    118124        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,
    120126                                               rect.width, rect.height))
    121127
    122128        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,
    124130                                               rect.width, rect.height))
    125131
    126132        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,
    128134                                               rect.width, rect.height))
    129135
    130136        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,
    132138                                               rect.width, rect.height))
    133139
    134140        # Get diagonal rects
    135141        if rect.x + rect.width < self.width - 1 and \
    136142                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,
    138144                                               rect.width, rect.height))
    139145
    140146        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,
    142148                                               rect.width, rect.height))
    143149
    144150        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,
    146152                                               rect.width, rect.height))
    147153
    148154        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,
    150156                                               rect.width, rect.height))
    151157
    152158        random.shuffle(new_rects)
    class Grid(SugarExt.Grid): 
    192198        collision_found = False
    193199        child_rect = self._child_rects[child]
    194200        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])
    196203            if c != child and intersection.width > 0:
    197204                if (c not in self._locked_children and
    198205                    c not in self._collisions):