[pygtk] Drag and drop with IconView

Andrew Steele steeley.uk at gmail.com
Sun Jun 6 23:08:17 WST 2010

On 1 June 2010 00:44, Robert Palmqvist <robert.palmqvist at home.se> wrote:

> I know how to do basic DnD with PyGTK but I struggle a bit with the
> IconView. What I really want to do is to enable DnD within and between
> IconViews. DnD, within should reorder icons within the same IconView and
> between should move the item between IconViews. I actually got it working,
> sort of, but it feels a bit hacky.
> I only used the signals 'drag-data-received', 'drag_data_get' and
> 'drag_data_delete'. Delete is a bit tricky since I have to keep track of DnD
> being between or within. It would also be nice if I could indicate where an
> icon is going while reordering within.
> I took a closer look at the IconView and found a whole set of methods that
> look really useful but I have no idea how to use them properly, and the
> documentation and FAQ doesn't help much either. So I have to turn to the
> mailing list and hope someone know how to properly implement DnD with the
> IconView.
> The methods I would like more information about are:
> set_drag_dest_item(path, pos)
> get_drag_dest_item()
> get_dest_item_at_pos(drag_x, drag_y)
> create_drag_icon(path)
> Thanks in advance / Robert

It took me a few days but I've written an example for this. I'll host it on
my website as its relatively long.


Probably not the best code in the world. One of the problems is that each
time the image is moved, it loads from disk again before inserting into the
IconView. On a small scale it isn't noticeable but if there were lots of
images in the IconView it could be slow.

Images can be dragged into it from the file manager, from there you can
rearrange as you like. It also supports dragging the image from the IconView
back to the file manager. It was tested on Ubuntu 9.10 and 10.04, not a clue
if will work on Windows or Mac.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20100606/54271549/attachment.htm 

More information about the pygtk mailing list