[pygtk] Re: TreeView reorderable

Jeffrey Barish jeff_barish at earthlink.net
Wed Jul 9 23:26:30 WST 2008

Seltzer wrote:

> Hi,
>   I have a tree view which contains a list of media items to be played,
>   and
> some information about them.
> I would like to be able to let the user re-order this list, but if i just
> use "set_reorderable(True)" than they can actually
> drop one item onto another, and make the dropped item the child of the
> item
> it was dropped onto.  I need to disable this some how, so that you can
> reorder the list, but not not drop one item into the other, just re
> arrange them.
> I am also restricted by pygtk version 2.4
> thanks for the help,
> felix.

You can define a drag_motion handler in which you detect drop position with
INTO (i.e., TREE_VIEW_DROP_INTO_OR_{AFTER,BEFORE}) and then invalidate the
position by calling the enable_model_drag_dest method with a bogus target.

    def on_drag_motion(self, treeview, drag_context, x, y, timestamp):
        dest_row = treeview.get_dest_row_at_pos(int(x), int(y))
        if dest_row is not None:
            path, drop = dest_row
            if drop in (gtk.TREE_VIEW_DROP_INTO_OR_AFTER,
                        [('invalid-position', 0, -1)],
                {enable model drag dest with valid target}

Jeffrey Barish

More information about the pygtk mailing list